variables for nested functions python code example

Example: python nested function

var = 0
name = 'absicsa'
 
def function_outer():
   # global var    ; no need to declare to call the value
   name = 'nabisco'
 
   def function_inner():
       global var  # need to declare global to modify the value
       name = 'outlet'
       var = 23
       print('name :',name, ', var :', var)
 
   print('name :', name, ', var :', var)
   function_inner()
 
print('name :', name, ', var :', var)
function_outer()
#>>> name : absicsa , var : 0
#>>> name : nabisco , var : 0
#>>> name : outlet , var : 23