Python: Which practice avoids a common mistake with Shallow vs Deep Copy?

Difficulty:

Medium

Questions:

1

Time Limit:

2 minutes

Passing Score:

100%

Question

Which practice avoids a common mistake with Shallow vs Deep Copy?

  1. Ignore the Shallow vs Deep Copy issue and rely on team discipline instead of clearer APIs or invariants.
  2. Silence the Shallow vs Deep Copy problem by using broad catches, hidden globals, or extra shared mutable state.
  3. Do not assume list.copy() or dict.copy() isolates nested mutable members, because inner objects still alias the original.
  4. Prefer the version of Shallow vs Deep Copy that makes behavior less predictable as long as the code still runs.

Hint

Look for the option that protects correctness instead of hiding the problem.

Answer and rationale

Correct answer: C. Do not assume list.copy() or dict.copy() isolates nested mutable members, because inner objects still alias the original.

Do not assume list.copy() or dict.copy() isolates nested mutable members, because inner objects still alias the original. This is a common failure mode in real Python code and a frequent interview follow-up.

Track: Python