filmov
tv
Nonlocal Keyword in Python #shortcut #keyword #python #programming #function #inner #outer #variable

Показать описание
Nonlocal Keyword in Python
The nonlocal keyword is used to access and modify a variable in the outer function from an inner function.
It is used to work with nested functions where we need to modify variables defined in an outer function.
def outer_func():
num = 10
def inner_func():
nonlocal num
num += 5
print("Inside inner function num:", num)
inner_func()
print("Inside outer function num:", num)
outer_func()
#non #local #keyword #in #python #programming #inner #function #modify #change #access #variables #print #def #nested #functions
#like #share #subscribe #mychannel
The nonlocal keyword is used to access and modify a variable in the outer function from an inner function.
It is used to work with nested functions where we need to modify variables defined in an outer function.
def outer_func():
num = 10
def inner_func():
nonlocal num
num += 5
print("Inside inner function num:", num)
inner_func()
print("Inside outer function num:", num)
outer_func()
#non #local #keyword #in #python #programming #inner #function #modify #change #access #variables #print #def #nested #functions
#like #share #subscribe #mychannel