ProgrammingVery hardWipro · Accenture · Capgemini pattern

What does the following Python 3 code print? def outer(): x = [10] def inner(): x[0] = 20 inner() return x print(outer())

  1. A. [10]
  2. B. [10, 20]
  3. C. []
  4. D. [20]

Correct answer: D. [20]

Mutating x[0] through the shared list object changes the underlying data itself, unlike rebinding a plain variable; no nonlocal is needed for mutation.

More Python Programming questions

Exams that ask this topic