8

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?

1

2 Answers 2

9

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

1
  • 5
    I seem to have misread reflection for (logical) complement.
    – greybeard
    Commented Nov 24, 2016 at 16:17
4

Reflection means swapping the operands, not applying "not" to the operator.

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

You were thinking the following

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

But that's not what reflection means.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.