comparison with None
Gary Herron
gherron at islandtraining.com
Wed Apr 18 18:48:38 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
>
No. using
if x is None:
is the recommended way.
Gary Herron
More information about the Python-list
mailing list