Home
MCQS
Python MCQ Quiz Hub
Python Mcq Set 4
Choose a topic to test your knowledge and improve your Python skills
1. What will be the output of the following Python code? x = ['ab', 'cd'] for i in x: i.upper() print(x)
[‘ab’, ‘cd’]
[‘AB’, ‘CD’]
[None, None]
none of the mentioned
2. What will be the output of the following Python code? x = ['ab', 'cd'] for i in x: x.append(i.upper()) print(x)
[‘AB’, ‘CD’]
[‘ab’, ‘cd’, ‘AB’, ‘CD’]
[‘ab’, ‘cd’]
None of the mentioned
3. What will be the output of the following Python code? i = 1 while True: if i%0O7 == 0: break print(i) i += 1
1 2 3 4 5 6
1 2 3 4 5 6 7
error
none of the mentioned
4. What will be the output of the following Python code? i = 5 while True: if i%0O11 == 0: break print(i) i += 1
5 6 7 8 9 10
5 6 7 8
5 6
error
5. What will be the output of the following Python code? i = 5 while True: if i%0O9 == 0: break print(i) i += 1
5 6 7 8
5 6 7 8 9
5 6 7 8 9 10 11 12 13 14 15 ….
error
6. What will be the output of the following Python code? i = 5 while True: if i%0O9 == 0: break print(i) i += 1
5 6 7 8
5 6 7 8 9
5 6 7 8 9 10 11 12 13 14 15 ….
error
7. What will be the output of the following Python code? i = 1 while True: if i%2 == 0: break print(i) i += 2
1
1 2
1 2 3 4 5 6 …
1 3 5 7 9 11 …
8. What will be the output of the following Python code? i = 2 while True: if i%3 == 0: break print(i) i += 2
2 4 6 8 10 …
2 4
2 3
error
9. What will be the output of the following Python code? i = 1 while False: if i%2 == 0: break print(i) i += 2
1
1 3 5 7 …
1 2 3 4 …
None of the mentioned
10. What will be the output of the following Python code? True = False while True: print(True) break
True
False
None
none of the mentioned
11. What will be the output of the following Python code? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)
0 1 2 0
0 1 2
error
none of the mentioned
12. What will be the output of the following Python code? i = 0 while i < 3: print(i) i += 1 else: print(0)
0 1 2 3 0
0 1 2 0
0 1 2
error
13. What will be the output of the following Python code? x = "abcdef" while i in x: print(i, end=" ")
a b c d e f
abcdef
i i i i i i …
error
14. What will be the output of the following Python code? x = "abcdef" i = "i" while i in x: print(i, end=" ")
no output
i i i i i i …
a b c d e f
abcdef
15. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: print(i, end = " ")
no output
i i i i i i …
a a a a a a …
a b c d e f
16. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: print('i', end = " ")
no output
i i i i i i …
a a a a a a …
a b c d e f
17. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: x = x[:-1] print(i, end = " ")
i i i i i i
a a a a a a
a a a a a
none of the mentioned
18. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x[:-1]: print(i, end = " ")
a a a a a
a a a a a a
a a a a a a …
a
19. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: x = x[1:] print(i, end = " ")
a a a a a a
a
no output
error
20. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x[1:]: print(i, end = " ")
a a a a a a
a
no output
error
21. What will be the output of the following Python code? x = 'abcd' for i in x: print(i) x.upper()
a B C D
a b c d
A B C D
error
22. What will be the output of the following Python code? x = 'abcd' for i in range(x): print(i)
a b c d
0 1 2 3
error
none of the mentioned
23. What will be the output of the following Python code? x = 'abcd' for i in range(len(x)): print(i.upper())
a b c d
0 1 2 3
error
1 2 3 4
24. What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): i.upper() print (x)
a b c d
0 1 2 3
error
none of the mentioned
25. What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): x[i].upper() print (x)
abcd
ABCD
error
None of the mentioned
26. What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): i[x].upper() print (x)
abcd
ABCD
error
none of the mentioned
27. What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): x = 'a' print(x)
a
abcd abcd abcd
a a a a
none of the mentioned
28. What will be the output of the following Python code snippet? x = 'abcd' for i in range(len(x)): print(x) x = 'a'
a
abcd abcd abcd abcd
a a a a
None of the mentioned
29. What will be the output of the following Python code? x = 123 for i in x: print(i)
1 2 3
123
error
none of the mentioned
30. What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for i in d: print(i)
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
31. What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d: print(x, y)
0 1 2
a b c
0 a 1 b 2 c
None of the mentioned
32. What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x, y in d.items(): print(x, y)
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
33. What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.keys(): print(d[x])
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
34. What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(x)
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
35. What will be the output of the following Python code? d = {0: 'a', 1: 'b', 2: 'c'} for x in d.values(): print(d[x])
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
36. What will be the output of the following Python code? d = {0, 1, 2} for x in d.values(): print(x)
0 1 2
None None None
error
None of the mentioned
37. What will be the output of the following Python code? d = {0, 1, 2} for x in d: print(x)
0 1 2
{0, 1, 2} {0, 1, 2} {0, 1, 2}
error
none of the mentioned
38. What will be the output of the following Python code? d = {0, 1, 2} for x in d: print(d.add(x))
0 1 2
0 1 2 0 1 2 0 1 2 …
None None None
none of the mentioned
39. What will be the output of the following Python code? for i in range(0): print(i)
0
no output
error
none of the mentioned
40. What will be the output of the following Python code? for i in range(2.0): print(i)
0.0 1.0
0 1
error
none of the mentioned
41. What will be the output of the following Python code? for i in range(int(2.0)): print(i)
0.0 1.0
0 1
error
none of the mentioned
42. What will be the output of the following Python code? for i in range(float('inf')): print (i)
0.0 0.1 0.2 0.3 …
0 1 2 3 …
0.0 1.0 2.0 3.0 …
none of the mentioned
43. What will be the output of the following Python code? for i in range(int(float('inf'))): print (i)
0.0 0.1 0.2 0.3 …
0 1 2 3 …
0.0 1.0 2.0 3.0 …
none of the mentioned
44. What will be the output of the following Python code snippet? for i in [1, 2, 3, 4][::-1]: print (i)
1 2 3 4
4 3 2 1
error
none of the mentioned
45. What will be the output of the following Python code snippet? for i in ''.join(reversed(list('abcd'))): print (i)
a b c d
d c b a
error
None of the mentioned
46. What will be the output of the following Python code snippet? for i in 'abcd'[::-1]: print (i)
a b c d
d c b a
error
none of the mentioned
47. What will be the output of the following Python code snippet? for i in '': print (i)
None
(nothing is printed)
error
none of the mentioned
48. What will be the output of the following Python code snippet? x = 2 for i in range(x): x += 1 print (x)
0 1 2 3 4 …
0 1
3 4
0 1 2 3
49. What will be the output of the following Python code snippet? x = 2 for i in range(x): x -= 2 print (x)
0 1 2 3 4 …
0 -2
0
error
50. What will be the output of the following Python code? for i in range(5): if i == 5: break else: print(i) else: print("Here")
0 1 2 3 4 Here
0 1 2 3 4 5 Here
0 1 2 3 4
1 2 3 4 5
Submit