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

Function in Python

Functions are named blocks of code that perform a specific task and can be called multiple times from different parts of a program. A function definition specifies the function's name, parameters, and body, while a function call passes arguments to the function and runs its code. Functions help reduce duplicated code and make programs more organized. A return statement can optionally return a value from the function call back to the calling code.
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)
17 views2 pages

Function in Python

Functions are named blocks of code that perform a specific task and can be called multiple times from different parts of a program. A function definition specifies the function's name, parameters, and body, while a function call passes arguments to the function and runs its code. Functions help reduce duplicated code and make programs more organized. A return statement can optionally return a value from the function call back to the calling code.
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
You are on page 1/ 2

FUNCTIONS

Functions are the named part of the program which can be invoked from
other parts of the program as many times as needed. Functions plays an
important role in helping to reduce the program code.
Function has three parts:
1. Function Definition
2. Function Call

THE FUNCTION DEFINITION


The function definition deals with purpose/task of the function. It tells the
python what the function does.
Syntax:
Def function_name(arguments):
Function body.
Example:
Def Add(a,b):
Print(a+b)

Arguments are the variables used in function.


You cannot skip variable name in function definition.
THE FUNCTION CALL
Function call passes the variable values to function definition, the number
of values must match the number of parameters.
Syntax:
Function_name(values)
Example:
Add (5,6)
Gives output
11

RETURN STATEMENT:
Return statement can be used to return function result to function call:
Def add(a,b):
Return (a+b)
Now return sends the value of sum back to function call this value may be
further used in program.
For example:
functionanswer = Add(6,11)
is equal to int functionanswer = 6+11

You might also like