`is` 和 `==` 之间的区别?

`is` 和 `==` 之间的区别?

问题描述:

可能的重复:
Python '==' vs 'is' 比较字符串,'is' 有时会失败,为什么?

在 Python 中,这两个语句有什么区别:

In Python, what is the difference between these two statements:

如果 x 是odp":

如果 x == odp":

== 运算符测试是否相等

is 关键字测试对象身份;我们是否在谈论同一个对象.请注意,多个变量可能引用同一个对象.

The is keyword tests for object identity; whether we are talking about the same object. Note that multiple variables may refer to the same object.