1var = 0
2name = 'absicsa'
3
4def function_outer():
5 # global var ; no need to declare to call the value
6 name = 'nabisco'
7
8 def function_inner():
9 global var # need to declare global to modify the value
10 name = 'outlet'
11 var = 23
12 print('name :',name, ', var :', var)
13
14 print('name :', name, ', var :', var)
15 function_inner()
16
17print('name :', name, ', var :', var)
18function_outer()
19#>>> name : absicsa , var : 0
20#>>> name : nabisco , var : 0
21#>>> name : outlet , var : 23
1def print_msg(msg):
2 # This is the outer enclosing function
3
4 def printer():
5 # This is the nested function
6 print(msg)
7
8 return printer # returns the nested function
9
10
11# Now let's try calling this function.
12# Output: Hello
13another = print_msg("Hello")
14another()