What is the difference between deep and shallow copy?
Answer Posted / 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 View All Answers
Explain the difference between a list and the tuple?
Tell me is there a switch or case statement in python?
The following is displayed by a print function call?
Write a program to convert all strings in list to integers?
What is the process of compilation and loading in python?
What is a program interpreter?
How to create a unicode string in python?
What is zip() function in python?
What is the use of pycharm?
Explain what is the common way for the flask script to work?
Why do we need operator overloading?
How will you get a titlecased version of string?
How much do python programmers make?
What is the __ init __ method used for?
With python, how do you find out which directory you are currently in?