Working With Functions PPT 1
Working With Functions PPT 1
INTRODUCTION
Function: - A function is a subprogram that act
on data and often return a value.
Python functions can belong to one of the
following three categories:
1. Built-in Function
2. Functions defined in modules
3. User defined functions
Reason of using FUNCTIONS
• A function is a named unit of a group of
program statements. This unit can be invoked
from other parts of a program.
• To make program handling easier, avoiding
ambiguity.
• To reduce the program size.
• To make program more readable and
understandable
EXAMPLE
• f(x): f can be termed as a function and x is its
argument.
• In a programming language, function can
have:
>arguments
>can perform certain functionality (some set of
stmts)
>can return a result
• Example:
f(x)=2x
CALLING/INVOKING /USING FUNCTION
• To use a function which has been already
defined, just write a function call statement.
• SYNTAX:
• EXAMPLE:
To call calcSomething(), the function call statement
will be:
#5 is being sent as an argument.
2)
print (calcSum ( 2 , 3 ))
a=5
b=6
print (calcSum ( a , b ))
d = 10
print (calcSum ( 9 , d ))
· Here a , b , d , 2 , 3 , 9 are “arguments” which is used in call function.
Parameters: - The values received in the
function definition header are called parameter
(or formal parameters or formal arguments).
For example: -
def calcSum ( x , y ):
:
Here x , y are “parameters”
Arguments in python can be one of these values:
>literals
>variables
>expressions
ARGUMENT: Actual parameter/actual argument
PARAMETER: formal parameter/formal argument
NOTE DOWN…..
IMPORTANT POINT……..
Example