practicepython.in
python exercises
171 exercises

Daily #18 · 16 October 2026

The error that still worked Hard

What does this print?

t = ([1],)
try:
    t[0] += [2]
except TypeError:
    pass
print(t)
  1. A([1, 2],)
  2. B([2],)
  3. C([1],)
  4. Draises TypeError
Show the answer

A: ([1, 2],)

Why: += on a list does two things: it extends the list in place, then assigns the result back into the tuple. The extend succeeds; the assignment fails, because tuples cannot be assigned to. The list inside was already changed.

Play today’s puzzle →