Pa1 Pa1 - 1 month ago 9
Python Question

Is there a difference between != and <> operators in Python?

I tried searching but could not find much about the

<>
operator.

https://www.tutorialspoint.com/python/python_basic_operators.htm mentions that
<>
is "similar" to the
!=
operator and does not say what is different or how it is different.

My tests seem to show it is the same:

a = 2, b = 3
>>> a != b
True
>>> a <> b
True
>>> b = 2
>>> a != b
False
>>> a <> b
False


Any help to understand this would be appreciated.

Answer

The python documentation says that they are equivalent.

The comparison operators <> and != are alternate spellings of the same operator. != is the preferred spelling; <> is obsolescent.

The <> operator has been removed from Python 3.