浅拷贝和深拷贝
浅拷贝:只会对最表层的进行拷贝,也就是相当于二者共有
深拷贝:会申请一块新的内存进行存储,相当于自己独占
对于dict的copy来说,是对最表层的键值对进行了深拷贝,举例来说:
a = {'one': 1, 'two': 2, 'three': [1,2,3]}
b = a.copy()
b从a拷贝过来的是{'one': 1, 'two': 2, 'three': []}
a = {'one': 1, 'two': 2, 'three': [1,2,3]}
b = a.copy()
a['three'].append(4)
print(a, b, sep="\n") # b['three']也被修改了
a['four'] = 4
print(a, b, sep="\n") # b['four']没有被添加
标签:sep,python,three,two,dict,拷贝,copy
From: https://www.cnblogs.com/zyh0831/p/17501738.html