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:
== Equal to - True if both operands are equal. x == y. != Not equal to - True if operands are not equal.
Not Equal Operator in Python If the values compared are equal, then a value of true is returned. If the values compared are not equal, then a value of false is returned. != is the symbol we use for the not equal operator.
The == operator compares the value or equality of two objects, whereas the Python is operator checks whether two variables point to the same object in memory. In the vast majority of cases, this means you should use the equality operators == and != , except when you're comparing to None .
Put simply: == determines if the values of two objects are equal, while is determines if they are the exact same object.
==
invokes __eq__()
. !=
invokes __ne__()
if it exists, otherwise is equivalent to not ==
.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