On Mon, Mar 3, 2014 at 4:51 PM, Tim Chase <python.l...@tim.thechases.com> 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:
    do_stuff()

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.

-- 
Jerry
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to