python'不是'运算符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4485180/
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
python 'is not' operator
提问by nos
I notice there is a comparison operator is not. Should I literally translate it into
我注意到有一个比较运算符is not。我应该把它从字面上翻译成
!=
instead of
代替
== not
采纳答案by Thomas K
To expand on what Ignacio said:
扩展伊格纳西奥所说的话:
a == band a != btest whether two objects have the same value. You can override an object's __eq__and __ne__methods to determine what that means.
a == b并a != b测试两个对象是否具有相同的值。您可以覆盖一个对象的__eq__和__ne__方法来确定这意味着什么。
a is band a is not btest whether two objects are the same thing. It's like doing id(a) == id(b)
a is b并a is not b测试两个对象是否相同。这就像在做id(a) == id(b)
回答by zsalzbank
A != B
means that "A is not equal toB", not "A is equal to notB".
表示“A不等于B”,而不是“A不等于B”。
回答by Ignacio Vazquez-Abrams
It's not relational comparison, it's identity. And it translates to not (A is B).
这不是关系比较,而是身份。它转换为not (A is B).
回答by 2r2w
python 2.7.3 documentation, 5.9. Comparisons:
The operators <, >, ==, >=, <=, and != compare the values of two objects.
运算符 <、>、==、>=、<= 和 != 比较两个对象的值。
and about operator isin the same chapter:
和有关运营商是在同一章:
The operators is and is not test for object identity: x is y is true if and only if x and y are the same object. x is not y yields the inverse truth value.
运算符是和不是测试对象身份:x is y 当且仅当 x 和 y 是同一个对象时才为真。x is not y 产生逆真值。

