6 ms·
This behavior can be replicated with any class that has two special methods: __neg__ that returns -1 and __sub__ that accepts ints and returns 1-other. For exa
by MadVikingGod 1y ago
This behavior can be replicated with any class that has two special methods:
__neg__ that returns -1 and __sub__ that accepts ints and returns 1-other.
For example if you make this class:
class _:
def __neg__(self):
return -1
def __sub__(self, other):
return 1-other
You get similar behavior:
>>> --_()
1
>>> _()--_()
2
Fun python for everyone.