comparison with None
Michael Hoffman
cam.ac.uk at mh391.invalid
Wed Apr 18 18:42:48 EDT 2007
brzrkr0 at gmail.com wrote:
> On Apr 18, 3:19 pm, Steven Howe <howe.ste... at gmail.com> wrote:
>> 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 >
>>
>> Steven Howe
>
> Is that any better than this?
>
> if x is None:
> # do something
> else:
> # do something else
To the contrary, it's not as good. "if x is None" is much clearer, and
probably faster.
--
Michael Hoffman
More information about the Python-list
mailing list