What is the difference between deep and shallow copy?



What is the difference between deep and shallow copy?..

Answer / chaitanya

• Shallow copy is used when a new instance type gets created and it keeps the values that are copied in the new instance. Whereas, deep copy is used to store the values that are already copied.

• Shallow copy is used to copy the reference pointers just like it copies the values. These references point to the original objects and the changes made in any member of the class will also affect the original copy of it. Whereas, deep copy doesn’t copy the reference pointers to the objects. Deep copy makes the reference to an object and the new object that is pointed by some other object gets stored. The changes made in the original copy won’t affect any other copy that uses the object.

• Shallow copy allows faster execution of the program and it depends on the size of the data that is used. Whereas, deep copy makes it slower due to making certain copies for each object that is been called.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Can a class run without constructor?

0 Answers  


Is python better than java?

0 Answers  


How do you sort in descending order in python?

0 Answers  


Difference between @staticmethod and @classmethod in python?

0 Answers  


What are literals in python?

0 Answers  






What is zip () in python?

0 Answers  


How do you include a string in python?

0 Answers  


What are accessors, mutators, and @property?

0 Answers  


Is python in demand?

0 Answers  


Explain me what does the <self> keyword do?

0 Answers  


How to convert a list into a string?

0 Answers  


How do you make a higher order function in Python?

1 Answers  


Categories