deep copy
In Python, deep copy refers to creating a new object that is a complete, independent clone of the original object, including all objects it refers to, recursively. This means that if you modify the deep-copied object or any nested objects inside it, the original object remains unchanged.
You typically use the copy.deepcopy() function from the copy module to make deep copies.
Deep copying is especially important when you’re working with complex, nested data structures such as lists of dictionaries or objects that contain other mutable objects.
See also: shallow copy
Example
Here’s how you can use deepcopy() to duplicate nested data structures:
>>> import copy
>>> original = {"numbers": [1, 2, 3], "info": {"name": "Alice"}}
>>> clone = copy.deepcopy(original)
>>> clone["numbers"].append(4)
>>> clone["info"]["name"] = "Bob"
>>> original
{'numbers': [1, 2, 3], 'info': {'name': 'Alice'}}
>>> clone
{'numbers': [1, 2, 3, 4], 'info': {'name': 'Bob'}}
As you can see, changes to clone don’t affect the original object, even in nested elements.
To see how this contrasts with a shallow copy, switch between the two modes in the diagram below and edit the clone to watch which inner objects each one shares with the original:
Related Resources
Tutorial
How to Copy Objects in Python: Shallow vs Deep Copy Explained
Understand the difference between shallow and deep copies in Python. Learn how to duplicate objects safely using the copy module and other techniques.
For additional information on related topics, take a look at the following resources:
By Leodanis Pozo Ramos • Updated June 26, 2026