Interesting behaviour of the assignment

Moshe Zadka moshez at zadka.site.co.il
Fri Dec 29 02:07:21 EST 2000


On Thu, 28 Dec 2000, "Alex Martelli" <aleaxit at yahoo.com> wrote:

> (Actually, in the case of None, the semantics of is and
> == are identical, but 'is' can be a tiny little bit faster).

No.

>>> class FoolAlex:
...         def __cmp__(self, other):
...             return cmp(None, other)
...
>>> FoolAlex() == None
1
>>> FoolAlex() is None
0

Which is why, in code I write, I always use "x is None" -- faster
and more reliable.
-- 
Moshe Zadka <sig at zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!




More information about the Python-list mailing list