Python 中的 != 和 <> 运算符之间有区别吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40211270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a difference between != and <> operators in Python?
提问by Pa1
I tried searching but could not find much about the <>
operator.
我尝试搜索,但找不到关于<>
运营商的太多信息。
https://www.tutorialspoint.com/python/python_basic_operators.htmmentions that <>
is "similar" to the !=
operator and does not say what is different or how it is different.
https://www.tutorialspoint.com/python/python_basic_operators.htm提到这<>
与!=
运营商“相似” ,并没有说明有什么不同或如何不同。
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.
任何帮助理解这一点将不胜感激。
回答by clemens
The python documentationsays that they are equivalent.
在Python文档说,他们是等价的。
The comparison operators
<>
and!=
are alternate spellings of the same operator.!=
is the preferred spelling;<>
is obsolescent.
比较运算符
<>
和!=
是同一运算符的替代拼写。!=
是首选拼写;<>
已经过时了。
The <>
operator has been removedfrom Python 3.
该<>
运算符已从 Python 3 中删除。