copy
The copy module provides functions for making shallow and deep copies of compound objects, including lists, tuples, dictionaries, and class instances.
copy(x)Makes a shallow copy of x by creating a new compound object and duplicating the members of x by reference.
deepcopy(x [, visit])Makes a deep copy of x by creating a new compound object and recursively duplicating all the members of x.visit is an optional dictionary that’s used to keep track of visited objects in order to detect and avoid cycles in recursively defined data structures. This argument is typically only supplied if deepcopy() is being called recursively, as described later.
A class can implement its own copy methods by implementing the methods __copy__(self) and __deepcopy__ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access