CH-03 working with Function
CH-03 working with Function
2.Defaults arguments
3.Keywords arguments
4.Variable Arguments
Positional The function call statement must match the number and order of
Arguments arguments as defined in the function definition, this is called the
Positional argument matching.
In this no value can be skipped from function call or you can’t change
the order of arguments also
:
then possible function calls for this can be:
check(x,y,z)#a gets value x, b gets value y, c gets value z
check(2,x,y) #a gets value 2, b gets value x, c gets value y
check(2,5,7) #a gets value 2, b gets value 5, c gets value 7
Default A parameter having default value in the function header is known
Arguments as a default parameter.
si=interest(6100,3,0.15)
# no argument missing with principle=6100 , time=3, rate=0.15
# Main Programme
4.n1=int(input(“Enter n1”)
5.n2=int(input(“Enter n2”)
6.s=sum(n1,n2)
7.print(s)
# main Programme
n1=int(input("Enter n1"))
n2=int(input("Enter n2"))
print(calsum(n1,n2))
OUTPUT
Enter n120
Enter n240
20
60
======================================================================
def show():
print(n3)
# main Programme
print(show())
OUTPUT
Error
=======================================================================
def run():
s=15 # local scope
print(s)
# main Programme
s=12 # Global Scope
print(s)
run()
print(s)
print("================================")
OUTPUT
12
15
12
=====================================================================
def run():
global s
s=90
print(s)
# main Programme
s=12 # Global Scope
print(s)
run()
print(s)
print(s)
OUTPUT.
10
1
====================================================================
# Q2.What is the output of the following code ?
a=1
def fun():
a=10
return a
# main programe
print(a)
print(fun())
print(a)
OUTPUT
1
10
1
a=1
def fun():
global a
a=50
return a
OUTPUT
1
50
50