The copy
module contains two functions that are used to copy objects, as shown in Example 1-64.
copy(object) => object
creates a
“shallow” copy of the given object. In this context,
shallow means that the object itself is copied, but if the object is a
container, the members will still refer to the original member
objects.
You can also make shallow copies of lists using the [:] syntax (full slice), and you can make copies of dictionaries using the
copy
method.
In contrast, deepcopy(object) => object
creates
a “deep” copy of the given object, as shown in Example 1-65. If the object is a
container, all members are copied as well, recursively.
Get Python Standard Library now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.