Back to feed

How to Copy Objects in Python: Shallow vs. Deep Copy

Real Python

EDITOR BRIEF

This article explains the difference between shallow and deep copies in Python. It shows how to duplicate objects safely using the copy module and other techniques.

INSIGHTS

Knowing when copies share data helps avoid bugs when you change nested objects. A good next step is to practice with small lists and dictionaries using copy.copy() and copy.deepcopy().

CodeFriends courses that build on this story. Practice in the browser with nothing to install.

COMMENTS

0/40
0/2000

Loading comments…