Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
How do you delete a key from a dictionary in Python?
1) del dict[key]
2) dict.remove(key)
3) dict.pop(key)
4) Both a and c
Answer : Both a and c
What is the output of print({1, 2, 3}.union({2, 3, 4}))?
1) {1, 2, 3, 4}
2) {1, 2, 3}
3) Error
4) {1, 2, 3, 2, 3, 4}
Answer : {1, 2, 3, 4}
How do you sort a list in Python?
1) list.sort()
2) sorted(list)
3) Both a and b
4) None of the above
Answer : Both a and b
What is the output of print("abc".capitalize())?
1) Abc
2) abc
3) Error
4) ABC
Answer : Abc
How do you define a method in a class in Python?
1) def method(self):
2) method(self):
3) def method():
4) None of the above
Answer : def method(self):
What is the output of print("Hello, World!".split(","))?
1) ['Hello', ' World!']
2) ['Hello, ' ' World!']
3) Error
4) ['Hello', ' World!']
Answer : ['Hello', ' World!']
How do you create a dictionary in Python?
1) dict = {}
2) dict = []
3) dict = ()
4) None of the above
Answer : dict = {}
What is the output of print(10 // 3)?
1) 3
2) 3.33
3) Error
4) 4
Answer : 3
How do you check if a string ends with a specific suffix?
1) string.endswith(suffix)
2) suffix in string
3) string.isuffix(suffix)
4) None of the above
Answer : string.endswith(suffix)
What is the output of print("Python"[0:3])?
1) Pyt
2) Python
3) Error
4) None
Answer : Pyt