Isn't None supposed to be false?

Will Ware wware at world.std.com
Tue May 2 23:50:32 EDT 2000


Albert Wagner (alwagner at tcac.net) wrote:
> >>> x = None
> >>> if x:
> ...     print 'false'
> ... else:
> ...     print 'true'
> ...
> true

This, and your other example, are correct behavior. It printed 'true'
because you put the "print 'true'" clause where it would be executed
if x was false. Perhaps you'd be less surprised by these examples:

>>> x = None
>>> if x:
...     print 'true'
... else:
...     print 'false'
...
false
>>> if x == None:
...     print 'true'
... else:
...     print 'false'
...
true

-- 
 - - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware	email:    wware @ world.std.com



More information about the Python-list mailing list