Which keyword is used to modify a variable from an enclosing function scope in Python?

Options

  • A. global
  • B. static
  • C. nonlocal
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. nonlocal

Detailed Explanation

The nonlocal keyword allows modification of a variable defined in the nearest enclosing function scope.