Difference between 'is' and '=='

Peter Hansen peter at engcorp.com
Mon Mar 27 08:07:01 EST 2006


Roy Smith wrote:
> In article <e08mr1$7lu$1 at news.lysator.liu.se>,
>  Joel Hedlund <joel.hedlund at gmail.com> wrote:
>>Which means that "is" comparisons in general will be faster than == 
>>comparisons.
> 
> I thought that == automatically compared identify before trying to compare 
> the values.  Or am I thinking of some special case, like strings?

You must be thinking of a special case:

 >>> class A:
...   def __cmp__(self, other): return 1
...
 >>> a = A()
 >>> a is a
True
 >>> a == a
False


-Peter




More information about the Python-list mailing list