Jerry Hill malaclypse2 at
Mon Mar 3 23:02:14 CET 2014

On Mon, Mar 3, 2014 at 4:51 PM, Tim Chase <python.list at> wrote:
> There are a couple use-cases I've encountered where "is" matters:
> 1) the most popular:
>   if foo is None:
>     do_stuff()

I know this is the one that always comes up, but honestly, I feel like
"is" doesn't matter here.  That code would be just as correct if it
was written as:

if foo == None:

The only time it would give you a different result from the "is"
version is if foo was bound to an object that returned True when
compared with None.  And if that were the case, I'm still not
convinced that you can tell from looking at those two lines of code
which one is buggy, except for the fact that there has been 20 years
of custom saying that comparing to None with equality is wrong.


More information about the Python-list mailing list