What does the `nonlocal` keyword do in Python?

Python Professional Hard

Python Professional — Hard

What does the `nonlocal` keyword do in Python?

Key points

  • `nonlocal` is used for variables in an outer function's scope
  • It enables nested functions to modify variables from the outer function
  • `nonlocal` is different from `global` in its scope-binding behavior

Ready to go further?

Related questions