Function Day6
Function Day6
Data=["P",20,"R",10,"S",30]
func(Data)
OUTPUT
9 60 P$R$S$
What will be the output of the
following snippets?
def func(L):
print(L[3:0:-1])
Data=[1,2,3,4,5]
func(Data)
(i) [4,3,2]
(ii) [4,3]
(iii) [4,3,2,1]
(iv) Syntax error
OUTPUT
(i) [4, 3, 2]
What will be the output of the
following snippets?
def fun():
l1=["Apple","Berry","Cherry","Papaya"]
l2=l1
l3=l1[:]
l2[0]="Guava"
l2[1]="Kiwi"
sum=0
for l in(l1,l2,l3):
if l[0]=="Guava":
sum+=1
if l[1]=="Kiwi":
sum=sum+20
print(sum)
fun()
OUTPUT
42
What will be the output of the
following snippets?
def dothis(x,I=[]):
for i in range(x):
I.append(i*i)
print(I)
dothis(2)
dothis(3,[3,2,1])
dothis(3)
OUTPUT
[0, 1]
[3, 2, 1, 0, 1, 4]
[0, 1, 0, 1, 4]
Identify which of these function
header will cause error and
why?
(i) def func (a=1,b):
(ii)def func(a=1,b,c=2):
(iii)def func(a=1,b=1,c=2):
(iv)def func(a=1,b=2,c=3,d):
FUNCTION HEADERS (I),(II),(IV) WILL
CAUSE ERROR BECAUSE NON DEFAULT
ARGUMENTS CAN’T FOLLOW DEFAULT
ARGUMENTS.
What will be the output of the
following snippets:
def add(x,y,z):
print(x+y+z)
def prod(x,y,z):
return(x*y*z)
a=add(6,16,26)
b=prod(2,3,6)
print(a,b)
OUTPUT
48
None 36