They're definitely different. The latter case evaluates not X
in a boolean context first and then checks to see if the two objects are the same object (either True
or False
).
Consider:
False is not []
This expression is trivially True
since False
and []
are quite clearly different objects. 1
vs.
False is (not [])
This expression is False
since not []
evalutes to True
and False
and True
are different objects.
Of course, this is just one example. It gets even easier to find examples if you don't use False
and True
explicitly as the second expression will always be False
and the first expression will (almost) always be True
...
3 is not 0 # True
3 is (not 0) # False
1Note that is not
is a single operator in the same vein as not in
.