Shallow copy vs deep copy
The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):
Shallow copy: constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original. Ie. uou have a new outer list, but inner lists are references.
Deep copy: constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original. Copies the nested lists also, so it is a recursive copy.
Assignment: does not copy. It simply sets the reference to the old data.
Example:
Using normal assignment operatings to copy:
Using a shallow copy:
Using a deep copy:
Last updated