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 中使用 'is' 要注意其判断值为对象,不要用来判断变量值是否相等

上一篇:mysql在线变更gtid复制


下一篇:吴恩达-机器学习笔记-第四章多变量线性回归(Linear Regression with Multiple Variables)