Newbie: is a variable defined?

Erik Max Francis max at alcyone.com
Fri Dec 20 19:09:57 EST 2002


Chad Netzer wrote:

>    The preferred way to test against None is with the "is" keyword,
> presumably because something can equal None without being None
> (from memory, if I'm wrong, someone correct this).

You're correct.  Someone could override __eq__ or __cmp__, for instance,
to make a custom instance test equal (==) to None.  But (unless None is
rebound), it could never test identical (is) to it.

It's a fairly minor quibble, I'd say, since only someone up to some
serious trickery (who's going to get his come-uppance) would make stoop
to making something equal to None, but nevertheless I myself always test
Noneness with is, not ==, and suggest that others do the same.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ That it will never come again is what makes life so sweet.
\__/ Emily Dickinson
    Rules for Buh / http://www.alcyone.com/max/projects/cards/buh.html
 The official rules to the betting card game, Buh.



More information about the Python-list mailing list