greybeard greybeard - 10 days ago 6
Python Question

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

In Basic customisation, the python docs state about comparison methods:


[no swapped-argument versions of these methods];
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.


I'd be less surprised by
__lt__()
and
__ge__()
being each other’s reflection(, as well as
__le__()
and
__gt__()
).

While the docs also state:


… no other implied relationships among the comparison operators, for example, the truth of
(x<y or x==y)
does not imply
x<=y
,


what, if anything, is the or would be a rationale for the reflection relations chosen?

Answer

Because a < b and b > a are equivalent, as are a <= b and b >= a.

Comments