Counterintuitive Python behavior

Skip Montanaro skip at pobox.com
Wed Apr 17 12:29:45 EDT 2002


    Greg> There should have been an operator in Python that says when
    Greg> objects are conceptually the same.  For the moment, call it "eq".
    Greg> The following would hold:

    Greg>     3 eq 3
    Greg>     not (3 eq 4)
    Greg>     a eq a            # PROVIDED a HAS A VALUE
    Greg>     "foo" eq "foo"
    Greg>     not ([] eq [])
    Greg>     not ({} eq {})
    Greg>     () eq ()

Guido's time machine strikes again:

    >>> 3 is 3
    True
    >>> not (3 is 4)
    True
    >>> a = "sdfsdf"
    >>> a is a
    True
    >>> "foo" is "foo"
    True
    >>> not ([] is [])
    True
    >>> not ({} is {})
    True
    >>> () is ()
    True

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)





More information about the Python-list mailing list