Python Function within Functions
A function that is defined inside another function is known as the inner function or nested function. Nested functions can access variables of the enclosing scope. Inner functions are used so that they can be protected from everything happening outside the function.
# Python program to
# demonstrate accessing of
# variables of nested functions
def f1():
s = 'I love w3wiki'
def f2():
print(s)
f2()
# Driver's code
f1()
Output:
I love w3wiki
Python Functions
Python Functions is a block of statements that return the specific task. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs, we can do the function calls to reuse code contained in it over and over again.
Some Benefits of Using Functions
- Increase Code Readability
- Increase Code Reusability