Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Nonlocal Variable | Variable Scope
course content

Зміст курсу

Intermediate Python: Arguments, Scopes and Decorators

Nonlocal VariableNonlocal Variable

So, now we understand the difference between global and local variables and have learned about nested functions. The <strong>nonlocal</strong> variable is used in nested functions. Let's look at an example:

Just as with global variables, we cannot change the variable created in outer_function inside inner_function without using the special keyword <strong>nonlocal</strong>.

The output is:

Все було зрозуміло?

Секція 4. Розділ 5
course content

Зміст курсу

Intermediate Python: Arguments, Scopes and Decorators

Nonlocal VariableNonlocal Variable

So, now we understand the difference between global and local variables and have learned about nested functions. The <strong>nonlocal</strong> variable is used in nested functions. Let's look at an example:

Just as with global variables, we cannot change the variable created in outer_function inside inner_function without using the special keyword <strong>nonlocal</strong>.

The output is:

Все було зрозуміло?

Секція 4. Розділ 5
some-alt