A shallow copy creates a new object but references the original data, while a deep copy creates a completely independent copy of the object and its nested data.
Suppose you have a recipe book with multiple pages, each containing a list of ingredients. A shallow copy of the book is like making a photocopy of the pages—if you modify the ingredients on one page, it will also change in the original book. In contrast, a deep copy is like creating an entirely new recipe book with separate pages, where you can modify the ingredients in the copy without affecting the original.
In Python, copying objects is common when replicating or duplicating data structures like lists, dictionaries, or custom objects. However, not all copying methods are the same.
There are two types of object copying:
Shallow copy
Deep copy