how to call a nested function in python code example
Example 1: python nested function
var = 0
name = 'absicsa'
def function_outer():
name = 'nabisco'
def function_inner():
global var
name = 'outlet'
var = 23
print('name :',name, ', var :', var)
print('name :', name, ', var :', var)
function_inner()
print('name :', name, ', var :', var)
function_outer()
Example 2: python define a function within a function
def print_msg(msg):
def printer():
print(msg)
return printer
another = print_msg("Hello")
another()
Example 3: nested functions in python
def print_msg(msg):
def printer():
print(msg)
return printer
another = print_msg("Hello")
another()