Is there a difference between != and <> operators in Python?
Question:
I tried searching, but could not find much about the <>
operator.
Python – Basic Operators 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
Answers:
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.
I tried searching, but could not find much about the <>
operator.
Python – Basic Operators 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
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.