I'm learning the concepts of programming languages.
I found the terminology "nonlocal" in python syntax.
What is the meaning of nonlocal in python?
The nonlocal variables are present in a nested block. A keyword nonlocal is used and the value from the nearest enclosing block is taken. For example:
def outer():
x = "local"
def inner():
nonlocal x
x = "nonlocal"
print("inner:", x)
inner()
print("outer:", x)
The output will be "nonlocal" both the times as the value of x has been changed by the inner function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With