Is there a difference between != and <> operato

2020-06-30 08:19发布

问题:

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.

回答1:

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.