0% found this document useful (0 votes)
9 views2 pages

Functions

Functions are reusable blocks of code defined using the syntax 'def functionName(arguments):'. The document provides an example of a function for addition and explains the difference between global and local variables, noting that local variables are inaccessible outside their function body.

Uploaded by

neilpython11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Functions

Functions are reusable blocks of code defined using the syntax 'def functionName(arguments):'. The document provides an example of a function for addition and explains the difference between global and local variables, noting that local variables are inaccessible outside their function body.

Uploaded by

neilpython11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like