copy — 浅拷贝和深拷贝操作

源代码: Lib/copy.py


Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other. This module provides generic shallow and deep copy operations (explained below).

接口摘要:

copy. copy ( obj )

返回浅拷贝为 obj .

copy. deepcopy ( obj [ , memo ] )

返回深拷贝的 obj .

copy. replace ( obj , / , ** changes )

创建相同类型的新对象如 obj , replacing fields with values from changes .

3.13 版添加。