Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
Which operator is used to concatenate two strings in Python?
1) +
2) *
3) &
4) concat
Answer : +
How do you define a static method in a class in Python?
1) @staticmethod def method_name():
2) def method_name():
3) static def method_name():
4) None of the above
Answer : @staticmethod def method_name():
What is the output of print({"a": 1, "b": 2}["a"])
1) 1
2) 2
3) Error
4) None
Answer : 1
Which of the following is a valid way to import specific functions from a module?
1) from module import function
2) import module.function
3) import function from module
4) None of the above
Answer : from module import function
How do you convert a string to an integer in Python?
1) int("string")
2) str("string")
3) convert("string")
4) None of the above
Answer : int("string")
What is the output of print(sum([1, 2, 3]))?
1) 6
2) Error
3) None
4) 5
Answer : 6
How do you create a class variable in Python?
1) self.variable
2) ClassName.variable
3) variable
4) None of the above
Answer : ClassName.variable
What is the output of print([1, 2] + [3, 4])?
1) [1, 2, 3, 4]
2) [4, 3, 2, 1]
3) Error
4) [1, 2, 4]
Answer : [1, 2, 3, 4]
How do you check if a string starts with a specific prefix?
1) string.startswith(prefix)
2) prefix in string
3) string.isprefix(prefix)
4) None of the above
Answer : string.startswith(prefix)
What is the output of print("1" == 1)?
1) True
2) False
3) Error
4) None
Answer : False