I came over this, where "not None" equals both True and False simultaneously.
>>> not None
True
>>> not None == True
True
>>> not None == False
True
At first I expected that this would be because of the order of operators, but however when testing a similar expression:
>>> not False
True
>>> not False == False
False
>>> not False == True
True
Can anyone explain why this is happening?
This is due to operator precedence. not none == True means not (None == True) means None != True, which is true. Similarly, None != False is also true. The value None is distinct from the booleans.
Your last two expressions mean False != False, which is false, and False != True, which is true.
This is indeed due to operator precedence.  not None == False will be evaluated as not (None == False).  None == False is False, which explains your results.
Try this instead:
>>> (not None) == True
True
>>> (not None) == False
False
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With