Difference between Deep and shallow cop

Python Programming Features, Python Syntax, Comments, Variables, Operators, Control Flow, Strings, Arrays, IO & File Handling, Python Object Oriented Programming.
Post Reply
Tejaswini
Posts: 36
Joined: Sun Mar 31, 2019 6:39 am

Difference between Deep and shallow cop

Post by Tejaswini » Wed Apr 17, 2019 5:30 pm

What is the difference between deep and shallow copy?

lokesh1
Posts: 36
Joined: Sun Mar 31, 2019 4:22 pm

Re: Difference between Deep and shallow cop

Post by lokesh1 » Wed Apr 17, 2019 5:32 pm

Shallow copy is used when a new instance type gets created and it keeps the values that are copied in the new instance. 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. Shallow copy allows faster execution of the program and it depends on the size of the data that is used.

Deep copy is used to store the values that are already copied. Deep copy doesn’t copy the reference pointers to the objects. It 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. Deep copy makes execution of the program slower due to making certain copies for each object that is been called.

Post Reply

Return to “Python Programming Fundamentals”