Shallow Copy in Python - How Does it Work? #Shorts

4K views Feb 21, 2023
codefather.tech

The Python copy module allows to create shallow copies and deep copies of objects. Below you can see the syntax for a shallow copy: new_object = copy.copy(original_object) A shallow copy creates a new compound object (in this example a list of lists) and references to the objects found in the original object are added to the new compound object. You will see what happens when you apply the concept of shallow copy to a list of lists. Learn more about copying lists in Python in the following Codefather article: https://codefather.tech/blog/copy-list-python/ Happy coding! Claudio