What is the output of the following code?
def func(): X = 'test' def nested(): nonlocal X X = 'Test' nested() print(X) func()
Test
The nonlocal statement means that the assignment to X inside the nested function changes X in the enclosing function's local scope.
Without this statement, this assignment would classify X as local to the nested function, making it a different variable.
The code would then print 'test' instead.