Function (CS)
Function (CS)
1. What is Function ?
A Function is a block of code which is used to perform specific task only runs
when it is called. Contains line of codes that are executed sequentially from top
to bottom by Phyton interpreter.
2. Advantages of Function :-
Program development made easy and fast
Program testing becomes easy
Code sharing becomes easy
Code reuse availability increases
Code read ability
Function facilate the factoring of code
3. Types Of Function :-
Built-in-Function
Functions define in modules
User defined functions
Note :- Function definition consists of the following components :-
Keyword “def” marks the start of Function( ) header.
A Function name to uniquely identify it.
Parameters(Arguments) through which we pass value to a function.
A colon(:) to mark the function header.
Optional Documentation string(doc string) to describe what function does.
One or more valid python statement that make up the function body.
Optional return statement to return a value from a function.
4. Argument And Parameter.
The value being passes through function call statement are called Argument or
Actual Argument or Actual Parameter.
The value received in function definition or header are called Parameter or
Formal Parameter or Formal Argument.
Example:-
def F1 (x,y):
print(x*y)
F1(20,30)
x and y are formal argument where 20 and 30 are actual argument.
5. Types of Actual Argument :-
Positional Argument When the function call statement must the number and
argument order as defined in ( ) definition is called positional argument .
def tuition (x,y,z):
return(x*y*z)
tuition(5,7,8)
Here, x is 5,y is 7,z is 8 positionally defined
Default Argument Python allows us to assign default value to function
parameter which is useful the specific parameter vaue.
def tuition (x=7,y,z):
return(x*y*z)
tuition(y=5,z=8)
Keyword Argument