import copy a = [1, 2, 3] # 浅拷贝,内存地址不变 b = a a[0] = 8 print(id(a)) #46204048 print(id(b)) #46204048 # 深拷贝,创建新的内存地址 c = copy.copy(a) print(id(c)) #45976232
import copy a = [1, 2, 3] # 浅拷贝,内存地址不变 b = a a[0] = 8 print(id(a)) #46204048 print(id(b)) #46204048 # 深拷贝,创建新的内存地址 c = copy.copy(a) print(id(c)) #45976232