← 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?
- A.NameError
- B.TypeError
- C.SyntaxError
- 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 →