0% found this document useful (0 votes)
24 views16 pages

07 - Python Functions 2 XII 2025-2026

Uploaded by

ps4861251
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)
24 views16 pages

07 - Python Functions 2 XII 2025-2026

Uploaded by

ps4861251
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/ 16

Computer Science

CLASS-XII (Code No. 083)

DPS RKP Computer Science Department


Python Functions - 2

2025-2026
Python Functions Part - 2

User Defined Functions


● default parameters
● positional parameters

DPS RKP Computer Science Department


2
Default Parameter
A formal parameter/argument, whose default value is assigned in the function
definition is known as a default parameter/argument. Once we provide a default
value in a formal parameter/argument, it becomes optional during the function
call, which means it is not mandatory to pass that argument/parameter during

DPS RKP Computer Science Department


function call.

def Line(N=5): def Exec(Num=2,Times=5):


print(N*'-') print(Num*Times,end="*")
Line() Exec(3)
Line(12) Exec()
Exec(4,8)

-----
------------ 15*10*32*
3
Default Parameter - Rule 1
Default parameter(s) can not be before non-default parameters.

def Calc(M=2,N):

DPS RKP Computer Science Department


print(M*N) SyntaxError: non-default
Calc(2) argument follows default
Calc() argument

Calc(4,8)

4
Default Parameter - Rule 2
While using multiple Default parameter(s), if we provide value to one of the
default argument through a function call, it overrides the leftmost default value of
the default parameters.

DPS RKP Computer Science Department


def Exec(P=1,Q=2,R=3): 18
print(P+Q+R) 20
Exec(5,10) 6
60
Exec(15)
Exec()
Exec(10,20,30) Call 1: P=5,Q=10,R=3
Call 2: P=15,Q=2,R=3
Call 3: P=1,Q=2,R=3
Call 4: P=10,Q=20,R=30
5
Default Parameter

def Line(CH="-",N=4): To draw a line with N number of a given


character CH. Assume the default value of CH as
print(CH*N) "-" and N as 4
Line("#",3)

DPS RKP Computer Science Department


Line('*') OUTPUT
Line() ###
Line(7) ****
Line("Hello") ----
28
Line((2,7)) HelloHelloHelloHello
(2, 7, 2, 7, 2, 7, 2, 7)

6
Default Parameter
def Line(CH,N=4): To draw a line with N number of a given character
print(N*CH) CH. Assume the default value of N as 4
Line("*")

DPS RKP Computer Science Department


Line("#",8) OUTPUT

Line(5,6) ****
Line() ########
30
----------
TypeError

7
Default Parameter
To find the payment for a worker at the
def Pay(Hrs=8): rate of Rs. 50/hour upto 8 hours and Rs.
if Hrs<=8: 100/hour after 8 Hours. Assume 8 Hrs. as
return Hrs*50 default hrs. for worker
else:

DPS RKP Computer Science Department


return 400+(Hrs-8)*100
print("Worker 1 gets",Pay()) OUTPUT
print("Worker 2 gets",Pay(7))
Worker 1 gets 400
print("Worker 3 gets",Pay(9))
Worker 2 gets 350
Worker 3 gets 500

8
Default Parameter
To calculate per over average for given
def Avg(Runs,Balls=6): number of Runs and Balls. Assume the
default Balls in over as 6
return Runs/Balls
R=int(input("Runs in current over:"))

DPS RKP Computer Science Department


print("Avg Run per Over:",Avg(R))
R=int(input("Runs in current over:"))
B=int(input("Balls in Over:")) OUTPUT
print("Avg Run per Over:",Avg(R,B))
Runs in current over:7
Avg Run per Over: 1.1666
Runs in current over:16
Balls in Over:7
Avg Run per Over: 2.2857

9
Default Parameter
def Resident(Loc=['Delhi','India']):
print("Resident of",Loc[0]+","+Loc[1])
Resident()
OUTPUT

DPS RKP Computer Science Department


Resident(['New York','US','Paris'])
Resident(('London','UK')) Resident of Delhi,India
Resident of New York,US
Resident({0:'Pune',1:"India"}) Resident of London,UK
Resident("AB") Resident of Pune,India
Resident("Mumbai","India") Resident of A,B
---------
TypeError Resident() takes
from 0 to 1 positional
arguments but 2 were given
10
Default Parameter
def Loc(Place="India"):
print("Destination",Place)
Loc()

DPS RKP Computer Science Department


Loc("USA") OUTPUT
Loc(110022) Destination India
Loc(("Delhi")) Destination USA
Loc(["Pune","Mah"]) Destination 110022
Destination Delhi
Loc({'City':'Jaipur'}) Destination ['Pune', 'Mah']
Destination {'City': 'Jaipur'}

11
Default Parameter

def Do(A=1,B=2,C=3): # Do(C=3,B=2,A=1) OUTPUT


return A+B+C
6
print(Do())
15

DPS RKP Computer Science Department


print(Do(10)) 48
print(Do(15,30)) 600
print(Do(100,200,300)) AMARAKBARANTHONY
print(Do("AMAR","AKBAR","ANTHONY")) [1, 2, 3, 4, 5, 5, 6, 7, 8]
print(Do([1,2],[3,4,5],[5,6,7,8])) (12, 10, 34, 1, 2, 3)
print(Do((12,),(10,34),(1,2,3))) ----TypeError

print(Do({1:20},{12:90},{100:200})) # Type Error

12
Default Parameter
def Some(Data=[12,30]):
print(Data[0]*5,Data[1]*10)
Some() #1 60 300
Some("AMAY") #2 AAAAA MMMMMMMMMM

DPS RKP Computer Science Department


Some(['A',10,'B',20]) #3 AAAAA 100
#4 Data['Name'] <> Data[0] Key Error
Some({'Name':'Ajay','Marks':35})
Some(25) #5 Type Error
Some(2.567) #6 Type Error
Some("A") #7 Index Error
Some(True) #8 Type Error
Some(34*31) #9 Type Error

13
Positional Parameter
In all the previous examples of functions before this slide, we have been using
positional parameter(s)/argument(s), where the values of the function call are
assigned in the same sequence of the corresponding identifier(s) used in the
parameter(s)/ argument(s) of the function (i.e. from left to right).

DPS RKP Computer Science Department


def FIND(I,J,K,L): I J K L I J K L
print(I*J-K*L)
FIND(5,4,2,3) 5 4 2 3 40 30 20 10
a,b,c,d=40,30,20,10
FIND(a,b,c,d) a b c d
14
1000
14
DOs and DONTs (Default Parameters)
def ReCap1(a,b,c=9): #1 Right
----
def ReCap2(a,b=90,c=9): #2 Right
----

DPS RKP Computer Science Department


def ReCap3(a=900,b=90,c=9): #3 Right
----
def ReCap4(a=900,b=90,c): #4 Wrong
----
def ReCap5(a,b=900,c): #5 Wrong
----
ReCap2(25) #6 Right
ReCap2(25,10) #7 Right
ReCap3(25,10,5) #8 Right
ReCap3() #9 Right
ReCap2() #10 Wrong
15
Happy Learning…

DPS RKP Computer Science Department


Thank you!
Department of Computer Science

16

You might also like