10.python Functions
10.python Functions
num = 10
number()
print( "Value of num outside the function:", num)
Python Function within Another Function
• Functions are considered first-class objects in Python. In a programming
language, first-class objects are treated the same wherever they are used.
They can be used in conditional expressions, as arguments, and saved in
built-in data structures. A programming language is considered to
implement first-class functions if it treats functions as first-class objects.
The concept of First Class functions is supported by Python.
• Inner or nested function refers to a function defined within another
defined function. Inner functions can access the parameters of the outer
scope. Inner functions are constructed to cover them from the changes
that happen outside the function. Many developers regard this process as
encapsulation.
Example
# Python code to show how to access variables of a nested functions
# defining a nested function
def word():
string = 'Python functions tutorial'
x=5
def number():
print( string )
print( x )
number()
word()