Counterintuitive Python behavior

Aahz aahz at pythoncraft.com
Wed Apr 17 13:28:33 EDT 2002


In article <mailman.1019061131.9382.python-list at python.org>,
Skip Montanaro  <skip at pobox.com> wrote:
>
>    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

As Greg pointed out, the first one and the last four are implementation
dependent.  Do *NOT* rely on them.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

What if there were no rhetorical questions?



More information about the Python-list mailing list