Tuesday, July 14, 2020

What is the difference between a Shallow copy and deep copy?


What is the difference between a Shallow copy and deep copy

 

In Python, if we want to go for faster execution of the program, depending on the size of the data, a shallow copy is preferred, where it is used as a reference pointer which copies the values by referring to the original objects and changes are made in any of the members of the class but the original copy is not affected by it.

 

Whereas, the deep copy concept in Python is used to store the values that are already copied. The reference pointers are not copied into the objects in case of deep copy, but it makes the reference to an object and the new object that is pointed by some other objects are stored.

 

Changes made in the original copy will not affect the other copy that is used in the object. With the application of deep copy concept, the execution of the program become slower, because of multiple copies of the same object that needs to be called for execution of the program again and again.

 

So, in nutshell, we can say that shallow copy helps in faster execution of the program without disturbing the original copy, whereas deep copy makes multiple copies of reference of references into new memory locations of the same instance and thus results in in slow execution of the program.

SMART SUBU

Author & Editor

Prof. (Dr) Subroto Chowdhury is a Data science and Technology Enthusiast, Independent Research Practitioner, Education Change Motivator, Ethical Investment Advisor and Analytics Consultant.Analytical Exposition interests him as an instrumentation process to make objective understanding of the complex Phenomenon and other decisions. He believes in making education more affordable, easy and pragmatic.

To Know More Click Here