what does is ?

Erik Max Francis max at alcyone.com
Thu Nov 28 14:05:35 EST 2002


Jonas Geiregat wrote:

> why is x is y 0 and a is b 1
> I don't get it it's the same code only different and bigger numbers

Identity is really irrelevant when you're talking about immutable
objects (like numbers and strings), since it really doesn't matter
whether or not two equal, immutable objects are really and truly the
same object (i.e., whether x is y).

For optimization, some immutable objects are "interned" so that you will
get a reference to the same object even though under normal
circumstances -- with a mutable object or without the optimization --
you would not.  When and where this happens is really an implementation
detail and is not something it's really constructive to concern yourself
with, since if you're dealing with immutable objects, the difference
between equality (x == y) and identity (x is y) is academic; equality
will be all that matters.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Some mistakes we must carry with us.
\__/ Speaker-to-Animals
    Blackgirl International / http://www.blackgirl.org/
 The Internet resource for black women.



More information about the Python-list mailing list