HomeInterview QuestionsWhat is the difference between a shallow copy and …

What is the difference between a shallow copy and a deep copy in Python?

🟡 Medium Conceptual Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

A shallow copy creates a new container object but does not recursively copy nested objects; it only copies references to the nested objects. A deep copy recursively copies all objects found within the original, producing a completely independent clone. Use the copy module: copy.copy() for shallow, copy.deepcopy() for deep. Shallow copies are O(n) in the size of the container, while deep copies are also O(n) but with additional overhead for each nested object.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500