编程语言
首页 > 编程语言> > python 中使用 'is' 要注意其判断值为对象,不要用来判断变量值是否相等

python 中使用 'is' 要注意其判断值为对象,不要用来判断变量值是否相等

作者:互联网

w3school 的解释:

The is keyword is used to test if two variables refer to the same object.
The test returns True if the two objects are the same object.
The test returns False if they are not the same object, even if the two objects are 100% equal.
Use the == operator to test if two variables are equal.

Python is Keyword
说的很清楚了,is 用来判断两个变量是否指向同一个对象,比较变量值应该用 ==

错误示范

标签:python,变量值,object,值为,two,same,returns,test,variables
来源: https://www.cnblogs.com/mrlonely2018/p/15507843.html