# 浅拷贝
a = [11,22,33]
b = a
print(id(a)) #内存地址13817864
print(id(b)) #内存地址13817864
# 深拷贝
import copy
c = copy.deepcopy(a)
print(id(a)) #内存地址13817864
print(id(c)) #内存地址14278728
从下面的代码可以看出,copy.deepcopy()深拷贝是递归依次拷贝引用
import copy
a = [11,22,33]
b = [44,55,66]
c = [a,b]
d = c
print(id(c))
print(id(d))
e = copy.deepcopy(c)
print(id(e))
a.append(44)
print(c[0])
print(e[0])
从下面的代码可以看出,copy.copy()深拷贝是只拷贝当前的引用,不会递归拷贝当前引用中的引用
import copy
a = [11,22,33]
b = [44,55,66]
c = [a,b]
d = c
print(id(c))
print(id(c))
e = copy.copy(c)
print(id(e))
a.append(44)
print(c[0])
print(e[0])