Generic (shallow and deep) copying operations.
通用(浅拷贝和深拷贝)复制操作
Interface summary:
import copy
x = copy.copy(y) # make a shallow copy of y
x = copy.deepcopy(y) # make a deep copy of y
Interface summary: import copy x = copy.copy(y) # make a shallow copy of y # 浅拷贝 x = copy.deepcopy(y) # make a deep copy of y # 深拷贝
The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances).
浅拷贝和深拷贝之间的区别仅与复合对象(包含其他对象的对象,如列表或类实例)相关。
A shallow copy constructs a new compound object and then (to the extent possible) inserts *the same objects* into it that the original contains.
浅拷贝构建一个新的复合对象,然后(尽可能地)将原始对象包含的“相同对象”插入其中。
A deep copy constructs a new compound object and then, recursively, inserts *copies* into it of the objects found in the original.
深拷贝构造一个新的复合对象,然后递归地将在原始对象中找到的对象的“副本”插入其中。
Two problems often ex