📘 Python MCQs
Q1. What is the output of the following code?
x = "Python"
print(x[1])
a) P
b) y
c) t
d) Error
Q2. Which of the following creates a tuple?
a) t = (1)
b) t = [1, 2]
c) t = (1,)
d) t = tuple[]
Q3. Which method is used to convert all characters in a string to
uppercase?
a) upper()
b) toupper()
c) upperCase()
d) capitalize()
Q4. What will be the result of:
"hello".replace("l", "L", 1)
a) heLLo
b) heLlo
c) heLL
d) hello
Q5. Which of these is not a valid list method?
a) append()
b) remove()
c) push()
d) insert()
Q6. What is the output of the following?
a = [1, 2, 3]
print(a * 2)
a) [1, 2, 3, 1, 2, 3]
b) [2, 4, 6]
c) [1, 2, 3, 2]
d) Error
Q7. Which of the following data types is immutable?
a) List
b) Dictionary
c) Set
d) Tuple
Q8. Which function returns the number of items in a list?
a) length()
b) size()
c) count()
d) len()
Q9. What is the result of:
s = "Hello World"
print(len(s))
a) 10
b) 11
c) 12
d) 9
Q10. What is the output?
"python".capitalize()
a) PYTHON
b) Python
c) python
d) PythoN
Q11. Which of the following removes all items from a list?
a) delete list
b) clear()
c) remove()
d) pop()
Q12. What will this slice return?
s = "Programming"
print(s[3:7])
a) gram
b) ogra
c) grammi
d) ramm
Q13. What is the output?
t = (1, 2, 3, 4)
print(t[1:3])
a) (2, 3)
b) [2, 3]
c) (1, 2, 3)
d) Error
Q14. Which method is used to join a list of strings into one string?
a) concat()
b) join()
c) merge()
d) append()
Q15. Sets do NOT allow:
a) integers
b) duplicate values
c) strings
d) booleans
Q16. What is the output of this code?
s = {1, 2, 3}
[Link](2)
print(s)
a) {1}
b) {1, 2}
c) {1, 2, 3}
d) Error
Q17. Which of the following creates an empty dictionary?
a) {}
b) []
c) dict()
d) a and c
Q18. What will this print?
d = {"a": 1, "b": 2}
print([Link]("c"))
a) Error
b) None
c) 0
d) "c"
Q19. How do you access value 20 from this dictionary?
d = {"x": 10, "y": 20}
a) [Link](20)
b) d[20]
c) d["y"]
d) d.y
Q20. Which of the following removes a key-value pair from a dictionary?
a) pop()
b) remove()
c) delete()
d) extract()
Q21. What is the output?
nums = [10, 20, 30]
[Link](1, 50)
print(nums)
a) [10, 50, 20, 30]
b) [50, 10, 20, 30]
c) [10, 20, 50, 30]
d) [10, 20, 30, 50]
Q22. Which method converts a string into a list of words?
a) explode()
b) break()
c) split()
d) listify()
Q23. What is the output?
list("ABCD")
a) ["ABCD"]
b) ["A", "B", "C", "D"]
c) ["A B C D"]
d) Error
Q24. Tuples can be used as dictionary keys because:
a) They are fast
b) They are immutable
c) They are sorted
d) They are unique
Q25. Which expression creates a set?
a) s = {}
b) s = {1, 2, 3}
c) s = set[]
d) s = (1, 2, 3)
Q26. What will be the output of the following code?
a = ["x", "y", "z"]
[Link](["p", "q"])
print(len(a))
a) 3
b) 4
c) 5
d) Error
Q27. Which of the following removes and returns the last element of a list?
a) pop()
b) shift()
c) remove()
d) pull()
Q28. What is the output?
s = "banana"
print([Link]("an"))
a) 1
b) 2
c) 3
d) 0
Q29. Which of the following statements is TRUE about sets?
a) They maintain insertion order
b) They allow duplicate items
c) They are indexed
d) They are unordered
Q30. What is the output of this code?
s = {1, 2, 3}
[Link]([4, 5])
print(s)
a) {1, 2, 3, 4, 5}
b) [1, 2, 3, 4, 5]
c) {1, 2, 3, [4, 5]}
d) Error
Q31. What is the result?
t = (10, 20, 30)
print(t * 2)
a) (20, 40, 60)
b) (10, 20, 30, 10, 20, 30)
c) (10, 10, 20, 20, 30, 30)
d) Error
Q32. What will this code output?
d = {"a": 1, "b": 2}
d["c"] = 3
print(len(d))
a) 2
b) 3
c) 4
d) Error
Q33. Which method returns a list of dictionary keys?
a) keys()
b) values()
c) items()
d) getKeys()
Q34. What is the output?
x = "hello world"
print([Link]())
a) Hello world
b) Hello World
c) HELLO WORLD
d) Hello-World
Q35. Choose the correct way to reverse a list a:
a) [Link]()
b) a = a[::-1]
c) reversed(a)
d) All of the above
Q36. What will be printed?
data = {"x": 10, "y": 20, "z": 30}
print(list([Link]())[1])
a) x
b) 10
c) 20
d) y
Q37. Evaluate the output:
a = [1, 2, 3]
b = a
[Link](4)
print(a)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4, 1, 2, 3]
d) Error
Q38. Which of the following converts a list to a set?
a) set(list)
b) set[]
c) [Link](list)
d) toSet(list)
Q39. What does this code print?
print({1, 2, 3} & {2, 3, 4})
a) {1, 4}
b) {2, 3}
c) {1, 2, 3, 4}
d) {}
Q40. What is the result?
word = "python"
print(word[-4:-1])
a) tho
b) thon
c) yth
d) tho_n
Q41. What is the output of the following code?
s = "hello world"
print("".join(sorted(s)))
a) dehllloorw
b) hellodlorw
c) hlloeorldw
d) Error
Q42. Which of the following correctly reverses string s?
a) s[::-1]
b) reverse(s)
c) [Link]()
d) rev(s)
Q43. What is the output?
s = "Programming"
print([Link]("m"))
a) 1
b) 2
c) 3
d) 0
Q44. What will this code output?
nums = {10, 20, 30}
[Link](20)
print(len(nums))
a) 2
b) 3
c) 4
d) Error
Q45. Which data structure is best for checking balanced brackets?
a) List
b) Dictionary
c) Set
d) Stack
Q46. What does this print?
letters = ['a', 'b', 'c', 'd']
print(letters[-3:-1])
a) ['b', 'c']
b) ['c', 'd']
c) ['a', 'b']
d) Error
Q47. Predict the output:
a = (1, 2, 3)
b = (1, 2, 3)
print(a is b, a == b)
a) True False
b) False True
c) True True
d) False False
Q48. What is the result of the following?
data = {"a": 1, "b": 2}
[Link]("c", 3)
[Link]("a", 100)
print(data)
a) {"a": 1, "b": 2, "c": 3}
b) {"a": 100, "b": 2, "c": 3}
c) {"a": 1, "b": 2}
d) Error
Q49. What does this code output?
arr = [1, 2, 3, 4]
x = [i*i for i in arr if i % 2 == 0]
print(x)
a) [1, 4, 9, 16]
b) [4, 16]
c) [2, 4]
d) [1, 9]
Q50. What does this code output?
def check_balance(expr):
stack = []
pairs = {')':'(', '}':'{', ']':'['}
for ch in expr:
if ch in [Link]():
[Link](ch)
elif ch in [Link]():
if not stack or [Link]() != pairs[ch]:
return False
return len(stack) == 0
print(check_balance("{[()]}"))
a) True
b) False
c) Error
d) None
[Link] Answer [Link] Answer
1 b 26 a
2 c 27 a
3 d 28 b
4 b 29 d
5 b 30 a
6 c 31 b
7 b 32 b
8 a 33 a
9 d 34 b
10 b 35 d
11 a 36 c
12 c 37 b
13 a 38 a
14 a 39 b
15 b 40 a
16 b 41 a
17 c 42 a
18 d 43 b
19 c 44 b
20 c 45 d
21 b 46 a
22 a 47 b
23 a 48 a
24 b 49 b
25 a 50 a