Why are (lt, gt) and (le, ge) reflections instead of (lt, ge) and (le, gt)?

In Basic Setup , python docs point to comparison methods:

[no versions of these methods]. rather, __lt__() and __gt__() are a reflection of each other, __le__() and __ge__() are a reflection of each other, and __eq__() and __ne__() are their own reflection.

I would be less surprised that __lt__() and __ge__() were a reflection of each other (as well as __le__() and __gt__() ).

The document also states:

... no other implied relationships between comparison operators, for example, true (x<y or x==y) does not imply x<=y ,

what, if anything, is or will be the rationale for the chosen reflection relationship?

+5
source share
2 answers

Because a < b and b > a equivalent, like a <= b and b >= a .

+5
source

Reflection means replacing operands without applying a "not" to the operator.

 __lt__(a,b) # if we don't know what to do, call return __gt__(b,a) 

You thought about the following

 __lt__(a,b) # if we don't know what to do return not __ge__(a,b) 

But that is not what reflection means.

+1
source

Source: https://habr.com/ru/post/1260292/


All Articles