"is" and "=="

Alexander Semenov sav at ulj.menatepspb.com
Tue Mar 11 18:57:08 EST 2003


> >>> "spam" is "spam"
> 1
> >>> "spam" is "sp" + "am"
> 0

But in case of rare insertion and often comparing
one can use intern():

>>> a = 'spam'
>>> b = 'sp'+'am'
>>> a is b
0
>>> a == b
1
>>> a = intern(a)
>>> b = intern(b)
>>> a is b
1

Alexander Semenov.






More information about the Python-list mailing list