Functions
Functions are a block of codes which can be reused many times
for related purpose.
Syntax:
def functionName(arguments):
Statements
return statement
Example:
num1 = int(input(‘Enter the value of a to add’)
num2 = int(input(‘Enter the value of b to add’)
def addition( a , b ):
c=a+b
return c
add = addition(num1 ,num2)
print(‘The addition of a an b is : %s’ %add)
Output:
Enter the value of a to add 2
Enter the value of b to add 3
The addition of a and b is : 5
Global variable & Local variables
Global variables are the variables that are defined outside
the function body.
Local variables are the variables that are defined inside the
function body.
Local variables cannot be accessed outside the function
body if you get that it will show error.