深浅拷贝:
li = [1,2,3,4,[5,6,7]] # 浅拷贝只拷贝一层元素
lst = li.copy()
print(li)
print(lst)
st = copy.deepcopy(li) # 深拷贝
对于复杂对象(嵌套)list =[1,2,3,[4,5,6]]
copy只能copy主对象,对于子对象copy等同于赋值(或理解为引用)
深浅拷贝:
li = [1,2,3,4,[5,6,7]] # 浅拷贝只拷贝一层元素
lst = li.copy()
print(li)
print(lst)
st = copy.deepcopy(li) # 深拷贝
对于复杂对象(嵌套)list =[1,2,3,[4,5,6]]
copy只能copy主对象,对于子对象copy等同于赋值(或理解为引用)