"is" and "=="

Thomas Wouters thomas at xs4all.net
Wed Mar 12 14:36:51 CET 2003


On Wed, Mar 12, 2003 at 02:57:08AM +0300, Alexander Semenov wrote:

> 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

One can, but it would still be better to use '==', as this works even when
intern (possible, in the future) would fail to do its job, and the identity
test is the first test == does.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!





More information about the Python-list mailing list