AI engineering glossary · Python advanced
What is nonlocal?
nonlocal: A keyword that tells a nested function that an assigned variable refers to one in the nearest enclosing function, not a new local one. It lets inner functions update outer state, such as counters in a closure.
nonlocal: an example
Inside inner(), nonlocal total then total += x updates total from the outer function.
Related terms
More Python advanced terms
Where you learn it
nonlocal is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.