Python None (Null) comparison. #53

Open
jfftck opened this Issue Apr 7, 2016 · 1 comment

Projects

None yet

2 participants

@jfftck
jfftck commented Apr 7, 2016

In Python x == None is not correct as anything that is false will make that true.

For example:
if x == None:
print 'True'
else:
print 'False'

x = 0 # True
x = 1 # False
x = [] # True
x = [1] # False
x = False # True
x = None # True

But this only works on None:
if x is None:
print 'True'
else:
print 'False'

x = 0 # False
x = 1 # False
x = [] # False
x = [1] # False
x = False # False
x = None # True

Please remove x == None as a valid way to check for None (Null) as it gives wrong information.

@clarkgrubb
Owner
$ python
Python 2.7.11 (default, Mar 20 2016, 17:15:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0 == None
False
>>> None == 0
False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment