O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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__ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required