ProgrammingHardTCS NQT · Infosys HackWithInfy · Product Company SDE

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

  1. A. None
  2. B. 20
  3. C. 0
  4. D. 10

Correct answer: D. 10

inner() creates its own local x=20, which shadows but never affects outer's x; outer's x remains 10 after inner() returns.

More Python Programming questions

Exams that ask this topic