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

本文最后更新于2015年7月25日,已超过 1 年没有更新,如果文章内容失效,还请反馈给我,谢谢!

缘由:

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=

声明: 除非注明,ixyzero.com文章均为原创,转载请以链接形式标明本文地址,谢谢!
https://ixyzero.com/blog/archives/2395.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注