Difference between Shallow and Deep copy of a class
Shallow Copy: Shallow repetition is quicker. However, it’s “lazy” it handles pointers and references. Rather than creating a contemporary copy of the particular knowledge the pointer points to, it simply copies over the pointer price. So, each the first and therefore the copy can have pointers that reference constant underlying knowledge.
Deep Copy: Deep repetition truly clones the underlying data. It is not shared between the first and therefore the copy.
Below is the tabular Difference between the Shallow Copy and Deep Copy:
Shallow Copy Deep Copy Shallow Copy stores the references of objects to the original memory address. Deep copy stores copies of the object’s value. Shallow Copy reflects changes made to the new/copied object in the original object. Deep copy doesn’t reflect changes made to the new/copied object in the original object. Shallow Copy stores the copy of the original object and points the references to the objects. Deep copy stores the copy of the original object and recursively copies the objects as well. Shallow copy is faster. Deep copy is comparatively slower.
Below is the program to explain the shallow and deep copy of the class.
['Red', 'Blue', 'Green'] ['Red', 'Blue'] ['Red', 'Blue', 'Green'] ['Red', 'Blue', 'Green']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course