3 ms·
After you're mastered all the available operators the real fun begins when you start writing your own operator methods on classes http://thepythonguru.com/pytho
by haney 8y ago
After you're mastered all the available operators the real fun begins when you start writing your own operator methods on classes http://thepythonguru.com/python-operator-overloading/ http://thepythonguru.com/python-operator-overloading/
The ability to override operators is one of the things I miss most from Python when I'm forced to write javascript.
- swpdkfn 8y agoThere could also be mention of the "right" variants e.g. __rmul__ vs. __mul__. https://stackoverflow.com/questions/5181320/under-what-circumstances-are-rmul-called https://stackoverflow.com/questions/5181320/under-what-circu... gives a rough sketch of what they're about.
- bhishan 8y agoThis is indeed a very helpful read. Thanks for the link.
- bhishan 8y agoThat's a great post. Thanks for the link. These methods do enhance classes to the best. I also made a short blog about magic methods. Could be relevant to someone reading the threads https://www.thetaranights.com/magic-methods-in-python/ https://www.thetaranights.com/magic-methods-in-python/