The nonlocal Keyword in Python


Modify variables in outer (enclosing) scopes.

Source Code

def outer():
    x = "local"
    def inner():
        nonlocal x
        x = "nonlocal"
    inner()
    print(x)

outer()
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments