comparison with None

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Apr 19 15:32:20 EDT 2007


Steven Howe a écrit :
(snip)
> I've read and found that 'None' comparisons is not always a good idea.
> Better to:
> from types import NoneType
> 
> x = None
> if type( x ) == NoneType:
>    # true
>    < code >
> else:
>    # false; do something else.
>    < more code >

Actually, None is garanteed to be a singleton, so the idiomatic way is 
to use an identity test:

if x is None:
   # code here

But this doesn't answer the OP...

HTH




More information about the Python-list mailing list