# "is" vs "=="
>>> a = [1, 2, 3]
>>> b = a
>>> a is b
True
>>> a == b
True
>>> c = list(a)
>>> a == c
True
>>> a is c
False
# • "is" 表达式为真,如果变量指向同一个对象
# • "==" 表达式为真,如果变量引用的对象相等
Python技巧之“is”对比“==”
点赞
收藏
Python技巧之“is”对比“==”
# "is" vs "=="
>>> a = [1, 2, 3]
>>> b = a
>>> a is b
True
>>> a == b
True
>>> c = list(a)
>>> a == c
True
>>> a is c
False
# • "is" 表达式为真,如果变量指向同一个对象
# • "==" 表达式为真,如果变量引用的对象相等