Couldn't find much on this. Trying to compare 2 values, but they can't be equal. In my case, they can be (and often are) either greater than or less than.
Should I use:
if a <> b:
dostuff
or
if a != b:
dostuff
This page says they're similar, which implies there's at least something different about them.
Quoting from Python language reference,
So, they both are one and the same, but
!=
is preferred over<>
.I tried disassembling the code in Python 2.7.8
And got the following
Both
<>
and!=
are generating the same byte codeSo they both are one and the same.
Note:
<>
is removed in Python 3.x, as per the Python 3 Language Reference.Quoting official documentation,
Conclusion
Since
<>
is removed in 3.x, and as per the documentation,!=
is the preferred way, better don't use<>
at all.Just stick to
!=
.<>
is outdated! Please check recent python reference manual.