Good afternoon, I will try to explain everything not with words but with examples
As we know, to use the variable X in this case, we need to update it via global
but what if the variable X is declared in a function and we want to get it from another function
If I use global, I get an error
CodePudding user response:
Use nonlocal
:
The nonlocal statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope excluding globals.