🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Scope and Closures: all 10 questions

Quiz: Scope and Closures · Question 4 of 10

What error do you get if an inner function does count += 1 on an enclosing variable without nonlocal?

What error do you get if an inner function does count += 1 on an enclosing variable without nonlocal?

  1. A.NameError
  2. B.TypeError
  3. C.SyntaxError
  4. D.UnboundLocalError
Answer & explanation

Correct answer: UnboundLocalError

The assignment makes count local to the inner function, and it is read before it has a value.

Can you get the rest right without peeking?

Take the timed Quiz: Scope and Closures quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →