Working With Functions - Set 2 - QP
Working With Functions - Set 2 - QP
for i in range(3):
1.What is the output of the following print(fun(i))
piece of code?
def find(a, **b): 9.What is the output of the following
print(type(b)) code?
find('letters',A='1',B='2') def xyz(k):
k = [1]
2.What is the output of the following q = [0]
code? xyz(q)
def abc(k): print(q)
k[0] = 1
q = [0] 10.How are variable length arguments
abc(q) specified in the function heading?
print(q)
a) one star followed by a valid identifier
3.How many keyword arguments can be b) one underscore followed by a valid
passed to a function in a single function identifier
call? c) two stars followed by a valid identifier
d) two underscores followed by a valid
4.What is the output of the following identifier
code?
def xyz(fname, val): 11.How are default arguments specified
print(fname(val)) in the function heading?
xyz(max, [1, 2, 3]) a) identifier followed by an equal to sign
xyz(min, [1, 2, 3]) and the default value
b) identifier followed by the default value
5.What is the output of the following within backticks (“)
code? c) identifier followed by the default value
def fun(): within square brackets ([])
return total + 1 d) identifier
total = 0
print(fun()) 12.How are required arguments specified
in the function heading?
6.What is the output of the following a) identifier followed by an equal to sign
code? and the default value
def fun(): b) identifier followed by the default value
total += 1 within backticks (“)
return total c) identifier followed by the default value
total = 0 within square brackets ([])
print(fun()) d) identifier
7.What is the output of the following 13.What is the output of the following
code? code?
def abc(x): def fun(x):
x = ['def', 'abc'] x[0] = ['def']
return id(x) x[1] = ['abc']
q = ['abc', 'def'] return id(x)
print(id(q) == abc(q)) q = ['abc', 'def']
print(id(q) == fun(q))
8.What is the output of the following
code? 14.What is the output of the following?
def fun(i, x=[]): def fun(i, x=[]):
x.append(i) x.append(x.append(i))
return x
for i in range(3): 21.What is the output of the code
y = fun(i) shown?
print(y) def f():
global a
15.The output of the code shown below print(a)
is: a = "hello"
def f1(): print(a)
x=15 a = "world"
print(x) f()
x=12 print(a)
f1()
22.What is the output of the code shown
16.What is the output of the code shown below?
below? def f1(a,b=[]):
def f1(): b.append(a)
x=100 return b
print(x) print(f1(2,[3,4]))
x=+1
f1() 23.What is the output of the code shown
below?
17.What is the output of the code shown def f(p, q, r):
below? global s
def san(x): p = 10
print(x+1) q = 20
x=-2 r = 30
x=4 s = 40
san(12) print(p,q,r,s)
p,q,r,s = 1,2,3,4
18.What is the output of the code f(5,10,15)
shown?
def f1(): 24.What is the output of the code shown
global x below?
x+=1 def f(x):
print(x) print("outer")
x=12 def f1(a):
print("x") print("inner")
print(a,x)
19.What is the output of the code shown f(3)
below? f1(1)
def f1(x):
global x 25.The output of code shown below is:
x+=1 x=5
print(x) def f1():
f1(15) global x
print("hello") x=4
def f2(a,b):
20.What is the output of the following global x
code? return a+b+x
x=12 f1()
def f1(a,b=x): total = f2(1,2)
print(a,b) print(total)
x=15
f1(4)