"is" and "=="

Matt Gerrans mgerrans at mindspring.com
Tue Mar 11 12:38:14 EST 2003


I don't think you want to be using "is" for general comparisons.   Is is to
check the identity of an object against another, to see if they really is --
er, are -- the same object.

For example:

>>> s = 'molify'
>>> t = 'mol' + 'ify'
>>> s is t
0
>>> s == t
1
>>> s = t
>>> s is t
1

So now we can tell the former president what the meaning of is is.

- Matt

"Dagur Páll Ammendrup" wrote:
> I was wondering when == should be used and when "is". I like using "is"
> when comparing strings and stuff but maybe I shouldn't?






More information about the Python-list mailing list