Difference between 'is' and '=='

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Hansen

    #46
    Re: Difference between 'is' and '=='

    On 3 Apr 2006 10:37:11 -0400 in comp.lang.pytho n, roy@panix.com (Roy
    Smith) wrote:
    [color=blue]
    >Adam DePrince <adam.deprince@ gmail.com> wrote:[color=green]
    >> It just happens that the
    >>logical operation
    >>
    >> (a is b ) -> (a == b )
    >>
    >>is always True.[/color]
    >
    >Only for small values of "always". You can always do pathological
    >things with operators:
    >
    >class Foo:
    > def __eq__ (self, other):
    > return False
    >
    >f = Foo()
    >print f is f
    >print f == f
    >
    >frame:play$ ./is.py
    >True
    >False
    >
    >This may even be useful. What if you were trying to emulate SQL's
    >NULL? NULL compares false to anything, even itself. To test for
    >NULLness, you have to use the special "is NULL" operator.[/color]

    Another instance where this may be useful is IEEE-754 NaN. I don't
    have fpconst to verify if that's the case, but I would expect
    NaN is NaN to be true, but NaN == NaN to be false.

    Regards,
    -=Dave

    --
    Change is inevitable, progress is not.

    Comment

    • Jon Ribbens

      #47
      Re: Difference between 'is' and '=='

      In article <e0rbun$70g$1@p anix2.panix.com >, Roy Smith wrote:[color=blue]
      > This may even be useful. What if you were trying to emulate SQL's
      > NULL? NULL compares false to anything, even itself.[/color]

      Strictly speaking, comparing NULL to anything gives NULL, not False.

      Comment

      • Duncan Booth

        #48
        Re: Difference between 'is' and '=='

        Adam DePrince wrote:
        [color=blue]
        > It just happens that the
        > logical operation
        >
        > (a is b ) -> (a == b )
        >
        > is always True.[/color]

        That is incorrect:
        [color=blue][color=green][color=darkred]
        >>> inf = 1e300*1e300
        >>> nan = inf-inf
        >>> nan is nan, nan==nan[/color][/color][/color]
        (True, False)

        Comment

        Working...