Result of ``a is b''

Andrew Koenig ark at acm.org
Wed Mar 17 17:54:12 CET 2004


"Robert Brewer" <fumanchu at amor.org> wrote in message
news:mailman.67.1079492061.742.python-list at python.org...
Andrew Koenig wrote:
> "Axel Boldt" <axelboldt at yahoo.com> wrote in message
> news:40200384.0403161255.7fca7a8c at posting.google.com...
>
> > Wow. So it seems that the action of "is" on immutables is
> unspecified
> > and implementation dependent, thus useless to the programmer.
>
> Hardly.  It has two fundamental properties, which can
> sometimes be useful:
>
>     1) If x and y refer to the same object, "x is y" yields True.
>
>     2) If "x is y" yields True, "x==y" also yields True.
> Equivalently, if
> "x==y" yields False, "x is y" also yields False.

Assuming nobody has overridden __eq__, of course. ;)

Indeed -- if == is redefined so as not to be an equivalence relation, all
bets are off.





More information about the Python-list mailing list