Learn Python MCQs
Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.
What is the output of print("a" + "b" * 2)?
1) abb
2) aabb
3) a + b + b
4) Error
Answer : abb
How do you create a string in Python?
1) s = "Hello"
2) s = 'Hello'
3) s = str("Hello")
4) All of the above
Answer : All of the above
Which keyword is used to create a function in Python?
1) def
2) function
3) create
4) func
Answer : def
What is the output of print("Hello"[0])?
1) H
2) Hello
3) h
4) Error
Answer : H
Which of the following is used to handle exceptions in Python?
1) try
2) except
3) finally
4) All of the above
Answer : All of the above
What is the output of print(2 * 3 ** 2)?
1) 18
2) 12
3) 36
4) 9
Answer : 18
Which of the following is not a valid variable name in Python?
1) my_variable
2) myVariable
3) my-variable
4) _myVariable
Answer : my-variable
How do you check if a string contains a substring in Python?
1) substring in string
2) string.contains(substring)
3) substring.contains(string)
4) string.has(substring)
Answer : substring in string
What is the output of print(list("abc"))?
1) ['a', 'b', 'c']
2) abc
3) Error
4) ['abc']
Answer : ['a', 'b', 'c']
How do you create a dictionary in Python?
1) myDict = {}
2) myDict = dict()
3) Both a and b
4) myDict = []
Answer : Both a and b