what does is ?

James T. Dennis jadestar at idiom.com
Wed Nov 27 15:11:22 EST 2002


Gerhard H?ring <gerhard.haering at opus-gmbh.net> wrote:
> Padraig Brady <Padraig at Linux.ie> wrote:
>> Gerhard H?ring wrote:
>>> Jonas Geiregat <kemu at sdf-eu.org> wrote:

>>>>I saw something
>>>>import string
>>>>string._StringType is str
>>>>what does this specially that IS

>>> The "is" operator compares object *identity*, rather than equality, which
>>> the "==" operator does.

>> Well why does the following happen on 2.2?
>> Is Python being clever about merging variables?

>> s1="123"
>> s2=s1[:]
>> s1 is s2 #true?

> Yes. Certain strings (not all) are being "interned". And certain ints 
> (not all)
> are interned, too:

 ...

> But it seems to me that the [:] slicing has an additional optimization, apart
> from interning.

 Youch!  I hope that *only* happens with immutables!  Of course calling
 "is" on names that are bound to immutables might not be useful in any
 practical sense.  On mutables in can alert you to the need for copy or
 deepcopy operations.  When would you care about object identity of 
 numbers or strings?




More information about the Python-list mailing list