"is" and "=="

Matt Gerrans mgerrans at mindspring.com
Tue Mar 11 18:38:14 CET 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
>>> s == t
>>> s = t
>>> s is t

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