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


Please Help Members By Posting Answers For Below Questions

What is ndarray in python?

443


What is difference between raw_input and input in python?

440


Can we concat bytes to str?

482


How to use *args and **kwargs in python?

524


What does the term ‘monkey patching’ refers to in python?

448






What is pyunit in python?

464


How is garbage handled in python?

461


What is pythonpath?

427


What does time time () do in python?

437


What is the use of numpy package?

479


How do you make 3d plots/visualizations using numpy/scipy?

436


Which module is used to control the gpio in python?

477


Explain how to delete a file in Python?

493


What is the concatenation?

469


What is the keyword to import a module in python?

449