Python3 doc, operator reflection

random832 at fastmail.us random832 at fastmail.us
Mon Oct 28 14:31:15 EDT 2013



On Mon, Oct 28, 2013, at 8:00, Johannes Bauer wrote:
> Hi group,
> 
> in http://docs.python.org/3/reference/datamodel.html#customization the
> doc reads:
> 
> > There are no swapped-argument versions of these methods (to be used when the left argument does not support the operation but the right argument does); rather, __lt__() and __gt__() are each other’s reflection, __le__() and __ge__() are each other’s reflection, and __eq__() and __ne__() are their own reflection.
> 
> But shouldn't __lt__ be the reflection or __ge__ and __gt__ the
> reflection of __le__?

No... a < b is b > a - you're thinking of the relationship between a < b
and not(a >= b), which is not the argument-swapping it is referring to.



More information about the Python-list mailing list