Python3 doc, operator reflection

Discussion in 'Python' started by Johannes Bauer, Oct 28, 2013.

  1. 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
     
    Johannes Bauer, Oct 28, 2013
    #1
    1. Advertising

  2. On Mon, Oct 28, 2013 at 11:00 PM, Johannes Bauer <> wrote:
    >> There are no swapped-argument versions of these methods (to be used whenthe 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 than1.

    ChrisA
     
    Chris Angelico, Oct 28, 2013
    #2
    1. Advertising

  3. Am 28.10.2013 13:23, schrieb Chris Angelico:
    > On Mon, Oct 28, 2013 at 11:00 PM, Johannes Bauer <> 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.


    Ah, I see. Thanks for clearing that up!

    Best regards,
    Joe
     
    Johannes Bauer, Oct 28, 2013
    #3
  4. Johannes Bauer

    Guest

    On Mon, Oct 28, 2013, at 8:00, Johannes Bauer wrote:
    > 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__?


    No... a < b is b > a - you're thinking of the relationship between a < b
    and not(a >= b), which is not the argument-swapping it is referring to.
     
    , Oct 28, 2013
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Wallace
    Replies:
    0
    Views:
    496
    John Wallace
    Jul 22, 2003
  2. Matt
    Replies:
    3
    Views:
    549
    Tor Iver Wilhelmsen
    Sep 17, 2004
  3. Praveen Chhangani

    Converting a org.jdom DOC to org.w3c DOC

    Praveen Chhangani, Aug 5, 2003, in forum: XML
    Replies:
    2
    Views:
    1,020
    Johannes Koch
    Aug 7, 2003
  4. News123
    Replies:
    0
    Views:
    309
    News123
    Feb 6, 2010
  5. Andrew Berg
    Replies:
    0
    Views:
    359
    Andrew Berg
    Jun 16, 2012
Loading...

Share This Page