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 == Truemeansnot (None == True)meansNone != True, which is true. Similarly,None != Falseis also true. The valueNoneis distinct from the booleans.Your last two expressions mean
False != False, which is false, andFalse != True, which is true.