Python中 is 和 == 的区别和用法


缘由:

http://www.reddit.com/r/Python/comments/3a2jlj/why_you_should_almost_never_use_is_in_python

搜索关键字:

python is == difference

参考链接:
参考解答:

‘is’ will return True if two variables point to the same object, ‘==” if the objects referred to by the variables are equal.


‘==’ is for value equality. Use it when you would like to know if two objects have the same value.

‘is’ is for reference equality. Use it when you would like to know if two references refer to the same object.


‘is’关键字一般是用来判断两者引用的object是否为同一个;

‘==’一般是用来判断两者引用对象的值是否相等。


 

=EOF=

,

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注