一、==和is的区别:
*==
比较两个对象是否相等
a = [11,22,33]
b = a
a == b
True
a = 23
b = a
a == b
True
a = [11,22,33]
b = [11,22,33]
a == b
True
a = 24
b = 24
a == b
True
*is
比较两个引用是否指向了同一个对象(引用比较)(大于256就是false)
a = 180
b = 180
a is b
True
a = 257
b = 257
a is b
False
a = 257
b = a
a is b
True
a = 180
b = a
a is b
True
a = [11,22]
b = [11,22]
a is b
False
a = [11,22]
b = a
a is b
True
二、深拷贝、浅拷贝
*浅拷贝:(拷贝了引用,并没有拷贝内容)
image.pngimage.png
*深拷贝:(对于一个对象所有层次的拷贝)
image.pngimage.png
网友评论