How Do Shallow Copy and Deep Copy Differ?

A deep copy creates a completely new object, along with all of its child objects, independent of the original. As a result, any changes made to the original object do not affect the deep copy.

You can create a deep copy using copy.deepcopy().

In contrast, a shallow copy creates a new object, but instead of duplicating the child objects, it only copies references to them from the original. This means that changes made to the original object will also be reflected in the shallow copy.

You can create a shallow copy using copy.copy().

Need Help?