Python is not equal to operator

I come from c-style languages, so I naturally used != As unequal, but when I came to Python, from the documentation I read, I learned that the <> operator was used for this purpose.

I have seen a lot of code lately using != , So my question is whether one of them is preferable to the other or one of them is deprecated.

In addition, I would like to know if there is a difference between the two.

+8
python deprecated not-operator
source share
4 answers

Python 2 supports both, the <> operator was removed in python 3.

There is no difference between the two, but != Is the preferred form .

+15
source share

From the official documents that you indicated

! = can also be written <>, but this is an obsolete use, reserved for backward compatibility only. New code should always use! =.

I believe that the rationale for the initial adoption of <> was that it looked more natural to someone coming from a mathematical background than the usual C-style != Operator.

+5
source share

I donโ€™t know what documentation you are reading, but I donโ€™t know what recommends <> over != . PEP8 , the basic style guide, does not mention such a recommendation.

+3
source share

Just for the record <> , at least version 1.4 , which was released in October 1996, has been deprecated since then.

0
source share

All Articles