is None or == None ?
Alf P. Steinbach
alfps at start.no
Fri Nov 6 08:35:14 EST 2009
* mk:
> Hello,
>
> Some claim that one should test for None using:
>
> if x is None:
>
> ..but the standard equality which is theoretically safer works as well:
>
> if x == None:
>
> So, which one is recommended?
>
> Can there be two None objects in interpreter's memory? Is testing for
> identity of some variable with None safe? Does language guarantee that?
> Or is it just property of implementation?
As I understand it, 'is' will always work and will always be efficient (it just
checks the variable's type), while '==' can depend on the implementation of
equality checking for the other operand's class.
Cheers & hth.,
- Alf
More information about the Python-list
mailing list