Reputation: 4092
I realized today while writing some Python that one could write the inequality operator as a!=b
or not a==b
. This got me curious:
Upvotes: 13
Views: 25569
Reputation: 3185
Be mindful of your parenthesis.
>>> not "test" == True
True
>>> not "test" and True
False
==
takes precedence over not
. But not
and and
have the same precedence, so
Upvotes: 10
Reputation: 799540
==
invokes __eq__()
. !=
invokes __ne__()
if it exists, otherwise is equivalent to not ==
.Upvotes: 21