FUNCTIONS
Functions are the already defined part of the program which can be recalled 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 basic three parts:
1. Function Definition
2. Function Call
3. THE FUNCTION DEFINITION
The FUNCTION DEFINATION:
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
Comments
Post a Comment