I would like to test the example of the use of the nonlocal statement specified in the answer on this question:
def outer():
x = 1
def inner():
Names listed in a nonlocal statement must not collide with pre-existing bindings in the local scope.
https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement
def outer():
x = 1
def inner():
nonlocal x
y = 2
x = y
print("inner: ", x)
inner()
print("outer: ", x)
>>> outer()
inner: 2
outer: 2