Python3 doc, operator reflection
Chris Angelico
rosuav at gmail.com
Mon Oct 28 08:23:32 EDT 2013
On Mon, Oct 28, 2013 at 11:00 PM, Johannes Bauer <dfnsonfsduifb at gmx.de> wrote:
>> 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__?
lt is the negation of ge, but it's the reflection of gt. Consider this:
1 < 2
2 > 1
If Python can't ask 1 if it's less than 2, it'll ask 2 if it's greater than 1.
ChrisA
More information about the Python-list
mailing list