On Wed, Jul 13, 2016 at 3:43 PM, Pavol Lisy
3. Questions around "only one possibilities how to write it" could be probably answered with this?
a
Those aren't the same, though. One is the interface, the other is the implementation. Dunder methods are for defining, not for calling. Also: rosuav@sikorsky:~$ python3 Python 3.6.0a2+ (default:4ef2404d343e, Jul 11 2016, 12:37:20) [GCC 5.3.1 20160528] on linux Type "help", "copyright", "credits" or "license" for more information.
class B: ... def __gt__(self, other): ... print("Am I greater than %s?" % other) ... return False ... a = 5 b = B() a < b Am I greater than 5? False
Operators can have multiple implementations (in this case, the interpreter found that "int < B" didn't have an implementation, so it switched it to b > a and re-evaluated). ChrisA