Python·100 questions

What is the difference between shallow copy and deep copy?

Answer
Shallow copy copies only the top level of the container.
Nested objects remain shared.
Deep copy recursively copies everything.
Shallow: list.copy(), copy.copy().
Deep: copy.deepcopy() (can be expensive).
Was this answer helpful?

More questions in this topic

Related questions from other topics