Which is more correct for compaing to None?

David Bolen db3l at fitlinxx.com
Sat May 12 22:10:28 EDT 2001


"Emile van Sebille" <emile at fenx.com> writes:

> I think I'd use if not foo:

Of course, that's a much wider check than comparing foo to "None",
since it will also be true for empty strings, empty tuples, empty
lists, and so on, including any object that defines an appropriate
special function to represent itself as being false (such as __eq__,
or __cmp__).

Doesn't make the check wrong, but just something to think about when
using it as opposed to something like "is None".

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list