practicepython.in
python exercises
171 exercises

Daily #13 · 11 October 2026

A copy that is not Medium

What does this print?

a = [[1], [2]]
b = a.copy()
b[0].append(9)
print(a)
  1. A[[1], [2], 9]
  2. B[[1], [2]]
  3. C[[9], [2]]
  4. D[[1, 9], [2]]
Show the answer

D: [[1, 9], [2]]

Why: copy() makes a new outer list holding the same inner lists. Appending to b[0] changes the list both of them point at. copy.deepcopy(a) copies all the way down.

Play today’s puzzle →