Is there a difference between `==` and `is` in Python?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Is there a difference between `==` and `is` in Python?相关的知识,希望对你有一定的参考价值。

There is a simple rule of thumb to tell you when to use == or is.

  • == 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.
>>> a = 500
>>> b = 500
>>> a == b
True
>>> a is b
False

 

 

注: 判断None的只能用xxx is None来做

 

ref: http://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is-in-python

https://segmentfault.com/q/1010000000150947

以上是关于Is there a difference between `==` and `is` in Python?的主要内容,如果未能解决你的问题,请参考以下文章

npm报错This is probably not a problem with npm. There is likely additional logging

Spirng 循环依赖报错:Is there an unresolvable circular reference?

人工智能有简单的算法吗?Appendix: Is there a simple algorithm for intelligence?

Other关于There is a cycle in the hierarchy!

Codeforces Round #352 (Div. 2) B. Different is Good

YES, There is No such thing as a free lunch