欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python is和==的区别

程序员文章站 2022-03-25 16:56:39
# is 比较的是内存地址 == 比较内容和数据类型 a = [1, 2, 3] b = a print(a is b) print(a == b) c = copy.deepcopy(a) print(a is c) print(a == c) True True False True 本文首发于 ......
# is 比较的是内存地址   == 比较内容和数据类型
a = [1, 2, 3]
b = a
print(a is b)
print(a == b)

c = copy.deepcopy(a)
print(a is c)
print(a == c)
-------------
true
true
false
true

本文首发于,博客园同步更新