Python3 doc, operator reflection

J

Johannes Bauer

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__?

Best regards,
Johannes
 
C

Chris Angelico

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 than1.

ChrisA
 
J

Johannes Bauer

Am 28.10.2013 13:23, schrieb Chris Angelico:
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.

Ah, I see. Thanks for clearing that up!

Best regards,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top