1. True/False: 5
(a) A Function can call another function or itself?
(b) Function can alter only mutable data types?
(c) Positional arguments must be written before keyword arguments.
(d) The values of default arguments must be passed from the calling function.
(e) Variable length argument values assign as a tuple in the function definition.
Ans:
(a) True
(b) True
(c) True
(d) False
(e) True
2. Fill in the blanks: 5
(a) _______ keyword is used to define a function
(b) By default a function return ------------
(c) randint() is a function of -------------- module.
(d) mode() is a function of ---------------- module.
(e) A function must be defined ---------- function calling.
Ans:
(a) def
(b) None
(c) random
(d) statistics
(e) before
3. Write the output of the following code. 1
L = [1, 5, 8, 6, 9]
print(L[3])
(a) 8
(b) 6
(c) 3
(d) None of these
Ans:
(b) 6
4. Write the output of the following code. 1 T1 = (1, 2)
T2 = (3, 4)
print (T1+T2)
(a) (1, 2, 3, 4)
(b) (4, 6)
(c) Error
(d) None of these
Ans:
(a) (1, 2, 3, 4)
5. Write the output of the following code. 1
D = {1:10, 2: 20, 3: 30, 1:40}
print(D.keys())
(a) dict_keys([1, 2, 3])
(b) [1, 2, 3] (c) (1, 2, 3)
(d) None of these
Ans:
(a) dict_keys([1, 2, 3])
6. Write the output of the following code. 1 S="Hello India"
print(len(S))
(a) 5
(b) 10
(c) 15
(d) None of these
Ans: (d) None of these Correct is 11
7. Which of the following is the correct function header? 1
(a) def add(a, b=10, c):
(b) def add(a=5, b= 10, c):
(c) def add(a, b=10, c=15):
(d) def add(a=5, b, c=15):
Ans: (c) def add(a, b=10, c=15):
8. What will be the output of the following code? 3 def check():
global num
num=1000
print(num)
num=100
print(num)
check()
print(num)
Ans: 100
1000
1000
9. What will be the output of the following code? 4 def drawline(char='$',time=5):
print(char*time)
drawline()
drawline('@',10)
drawline(65)
drawline(chr(65))
Ans: $$$$$
@@@@@@@@@@
325
AAAAA
10. What will be the output of the following code? 4 def Fun1(mylist):
for i in range(len(mylist)):
if mylist[i]%2==0:
mylist[i]/=2
else:
mylist[i]*=2
list1 = [21, 20, 6, 7, 9, 18, 100, 50, 13]
Fun1(list1)
print(list1)
Ans: [42, 10.0, 3.0, 14, 18, 9.0, 50.0, 25.0, 26]
11. What will be the output of the following code? 4 X = 100
def Change(P=10, Q=25):
global X
if P%6==0:
X+=100
else:
X+=50
Sum=P+Q+X
print(P,'#',Q,'$',Sum)
Change()
Change(18,50)
Change(30,100)
Ans: 10 # 25 $ 185
18 # 50 $ 318
30 # 100 $ 480
12. What will be the output of the following code? 5 def Alter(M,N=50):
M = M + N
N = M - N
print(M,"@",N)
return M
A=200
B=100
A = Alter(A,B)
print(A,"#",B)
B = Alter(B)
print(A,"@",B)
Ans: 300 @ 200
300 # 100
150 @ 100
300 @ 150
13. What is the difference between actual and formal parameter? 1
14. What are the different types of function arguments? Explain each with example. 4