What is Python's copy module?
Why Interviewers Ask This
This tests whether you can apply Python knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
The copy module provides object copying functions. copy.copy(obj) creates a shallow copy — a new object whose contents are references to the same objects as the original. For containers (lists, dicts), a new container is created but the elements inside are still the same objects. copy.deepcopy(obj) creates a deep copy — recursively copies all nested objects so the copy is completely independent. Deep copy handles circular references automatically using a memo dict. Custom copy behavior: implement __copy__(self) for shallow and __deepcopy__(self, memo) for deep copy. Performance: deep copy is significantly slower than shallow copy. Avoid deep-copying large structures unnecessarily. In practice: for immutable objects (int, str, tuple), copying is unnecessary since they cannot change. For mutable nested structures that you need to modify independently, use deep copy.
Pro Tip
This topic has Python-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.