In Python, we can create a nested function inside a function. We can use the nested function to perform complex tasks multiple times within another function or avoid loop and code duplication.
# outer function
def outer_fun(a, b):
square = a ** 2
# inner function
def addition(a, b):
return a + b
# call inner function from outer function
add = addition(a, b)
# add 5 to the result
return add + 5
result = outer_fun(5, 10)
print(result)
Solution:
In Python, we can create a nested function inside a function. We can use the nested function to perform complex tasks multiple times within another function or avoid loop and code duplication.
need an explanation for this answer? contact us directly to get an explanation for this answer