What is the difference between the shallow copy and deep copy in python?



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

Answer / Bhajan Veer Singh

A shallow copy creates a new object that references the original object's attributes. If the original object contains lists or dictionaries, those will not be copied but instead reference the same data. A deep copy, on the other hand, creates a new object and recursively copies all of its attributes, including nested lists and dictionaries. In Python, you can use `copy.deepcopy()` to perform a deep copy.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What is uuid used for?

1 Answers  


Which methods/functions do we use to determine the type of instance and inheritance?

1 Answers  


Under what circumstances would von use a while statement rather than for?

1 Answers  


What tools are available to perform the static analysis?

2 Answers  


How can I execute arbitrary python statements from c?

1 Answers  


How do you get a list of all the keys in a dictionary in python?

1 Answers  


What is __ new __ in python?

1 Answers  


How python maintains conditional blocks?

1 Answers  


What is the best flask or Django

1 Answers  


Write a program to read and write the binary data using python?

1 Answers  


Is it easier than Django bottle?

1 Answers  


What is syntax in python programming?

1 Answers  


Categories