hyperpolyglot icon indicating copy to clipboard operation
hyperpolyglot copied to clipboard

Python None (Null) comparison.

Open jfftck opened this issue 9 years ago • 1 comments

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.

jfftck avatar Apr 07 '16 15:04 jfftck

$ 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

clarkgrubb avatar Apr 08 '16 03:04 clarkgrubb