Result of ``a is b''

Andrew Koenig ark at acm.org
Tue Mar 16 20:54:46 EST 2004


"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.

> Maybe one could redefine "is" on immutables as follows: for strings
> and numbers it acts as "==", for tuples it acts as componentwise "is".
> That would be a more useful operator IMHO.

Can you give a realistic example of code that would benefit from such a
change?





More information about the Python-list mailing list