Result of ``a is b''

Josiah Carlson jcarlson at nospam.uci.edu
Mon Mar 15 20:37:33 EST 2004


>   >>> a = (1,2)
>   >>> b = (1,2)
>   >>> a is b
>   False
>   >>> a = "12"
>   >>> b = "12"
>   >>> a is b
>   True

Unless you care whether two names point to the same object, don't use 
'is'.  Instead compare for equality with '=='.  That should work like 
you want it to:
 >>> a = (1,2)
 >>> b = (1,2)
 >>> a == b
True
 >>> a = "12"
 >>> b = "12"
 >>> a == b
True

It will also handle the cases that Andrew points out.

  - Josiah



More information about the Python-list mailing list