clarkgrubb / hyperpolyglot

hyperpolyglot.org
Other
473 stars 94 forks source link

Python None (Null) comparison. #53

Open jfftck opened 8 years ago

jfftck commented 8 years ago

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 commented 8 years ago
$ 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