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?
Asked
Active
Viewed 369 times
0
TheRavenSpectre
- 367
- 2
- 11
-
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 Aug 19 '22 at 06:03
1 Answers
1
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
Ari157
- 95
- 4
- 16