Friday, April 26, 2013

Don't Use == null - Python

http://stackoverflow.com/questions/3289601/null-object-in-python

It says not to use == to check for "none-ness". It's better to use:

if variable is none:
    <your code>

Why? "And the reason for choosing egg is None over egg == None: The latter can be overloaded, and is likely to break when comparing valid object with None (depends on how it's implemented, but you don't expect everyone to take comparisions with None into account, do you?), while is always works the same."

No comments:

Post a Comment