Home / Python Tips Generated By ChatGPT / The nonlocal Keyword in Python Use nonlocal within nested functions to modify variables in the nearest enclosing scope. Source Code def outer(): x = "local" def inner(): nonlocal x x = "nonlocal" inner() print(x) # nonlocal outer()