Q6: What is the difference between copy.copy() and copy.deepcopy()?

  • Shallow Copy (copy.copy()): Creates a new container object, but populates it with references to child objects inside the original.
  • Deep Copy (copy.deepcopy()): Recursively duplicates the container AND all nested child objects, constructing completely independent object graphs.
Key Takeaways
  • Shallow copy duplicates top-level container only.
  • Deep copy duplicates container and all nested child object references recursively.
Knowledge Check

If you modify a nested list inside a shallow copied object, does the original object's nested list update?