Python Programming MCQs
10. Output?
(Medium to Hard) d={1:"A",2:"B"}; print([Link](3,"C"))
a) Error b) None c) C d) 3
1. What will be the output? Ans: c
x = 10; y = 3; print(x / y)
a) 3 b) 3.0 c) 3.333 d) 11. Output?
3.3333333333333335 lst=[1,2,3]; print(lst*2)
Ans: d a) [2,4,6] b) [1,2,3,1,2,3] c) Error d) None
Ans: b
2. Which data type is immutable?
a) List b) Dict c) Tuple d) Set 12. Output?
Ans: c x=[1,2,3]; y=x; [Link](4); print(x)
a) [1,2,3] b) [4] c) [1,2,3,4] d) Error
3. What is the output? Ans: c
x = True + False + True; print(x)
a) 1 b) 2 c) 0 d) True 13. Which loop best when iterations
Ans: b unknown?
a) for b) while c) nested d) infinite
4. What does break do? Ans: b
a) Skip loop b) Exit loop c) Restart loop d)
Stop program 14. Output?
Ans: b def fun(x,y=2): return x*y; print(fun(5))
a) 5 b) 10 c) 15 d) Error
5. What is returned if function has no return? Ans: b
a) 0 b) False c) None d) Error
Ans: c 15. What type of function is lambda?
a) Built-in b) Recursive c) Anonymous d)
6. Output? Generator
for i in range(1,5): print(i,end=" ") Ans: c
a) 1 2 3 4 b) 0 1 2 3 c) 1 2 3 4 5 d) Error
Ans: a 16. Output?
i=1
7. Output? while i<5:
lst=[1,2,3]; [Link]([4,5]); print(len(lst)) print(i); i+=2
a) 3 b) 4 c) 5 d) Error a) 1 3 b) 1 2 3 4 c) 2 4 d) Infinite
Ans: b Ans: a
8. Output? 17. Output?
t=(1,2,3); t[0]=10 import numpy as np; a=[Link]([1,2,3]);
a) (10,2,3) b) Error c) None d) (1,2,3) print(a*2)
Ans: b a) [2,4,6] b) [1,2,3,1,2,3] c) Error d) None
Ans: a
9. Dictionary keys must be:
a) Mutable b) Immutable c) List d) Set 18. ndarray stands for?
Ans: b a) Numeric data array b) n-dimension array
c) node array d) none
Ans: b
19. Output?
[Link](3)
a) [0,0,0] b) (0,0,0) c) array([0.,0.,0.]) d)
Error
Ans: c
20. Shape of [Link]([[1,2],[3,4]])?
a) (4,) b) (2,2) c) (1,4) d) (4,1)
Ans: b