Nested Function
Last Updated: 01th September 2025
A nested function is a function that is defined inside another function.
📝 Syntax:
def outer_function():
def inner_function():
# inner function body
#..
# outer function body
# inner_function()
#
#When Call it
outer_function()
Example 1.
def outer_function():
def inner_function():
print("Inner function called")
print("Outer function called")
inner_function()
outer_function()
Example 2.
def outer_function():
def inner_function():
print("Inner function called")
print("Outer function called")
return inner_function
inner_function=outer_function()
inner_function()
#Direct call
outer_function()()