2015-09-23 34 views
-4

学习python。我一直怀疑使用以下运算符:Operator!= vs <>

!= —> Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. 
<> —> Checks if the value of two operands is equal or not, if values are not equal then condition becomes true. 

以上的定义是正确的(referred from book)?如果是的话,当我们使用两个操作员。请分享你的经验与正确的情况!

回答

3

the documentation -

的形式<>!=是等价;为了与C一致,优选!=;其中!=在下面提及<>也被接受。 <>拼写被认为是过时的。

(重点煤矿)

他们是等价的,但你应该使用!=。在Python 3.x中也不存在运算符<>

+2

但是在Python 3中,我可以这样做:'from __future__ import barry_as_FLUFL'。 –

+0

:-),它不应该是'__past__'吗? –

3

Python standard library Docs

!注意:

  1. =也可以写<>,但是这是一个过时的使用率只保留向后兼容。新代码应该始终使用!=。

所以对平等检查时,你应该总是使用!=操作。