+ 1
Python create new operator
theres a lot of math operators. like ** is pow. how to create the new one like *** ? i cant find the answer in internet
2 Answers
+ 2
Unfortunately python can't define new operators... You can overload the current operators in a class with magic functions. Maybe the lambda is also useful for you :
mul = (lambda x y: x * y )
mul 3 2 # gives 6
Or even with a little hack:
mul = Infix(lambda x y: x * y )
3 |mul| 2 # gives 6
Source how to get Infix working:
http://code.activestate.com/recipes/384122/
Similar stack overflow question :
https://stackoverflow.com/questions/932328/python-defining-my-own-operators
0
Stack overflow is in general a good website for those kind of questions