For example, there already exist +, -... which can be overwritten using __add__ and __sub__ respectively. However, is it possible to write a new operator like . or x?
-
2No. There are only specific operators that can be overwritten. Python doesn't let you add your own. You cannot change the grammar of the language.Frank Yellin– Frank Yellin2022-08-19 06:03:54 +00:00Commented Aug 19, 2022 at 6:03
Add a comment
|
1 Answer
No, you cannot, although there's some weird hackyness than can be done,
But if you want smt like:
1 x 2
You'll have to make a preprocessor