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 : Option 1

How do you create a string in Python?

1) s = "Hello"

2) s = 'Hello'

3) s = str("Hello")

4) All of the above

Answer : Option 1

Which keyword is used to create a function in Python?

1) def

2) function

3) create

4) func

Answer : Option 1

What is the output of print("Hello"[0])?

1) H

2) Hello

3) h

4) Error

Answer : Option 1

Which of the following is used to handle exceptions in Python?

1) try

2) except

3) finally

4) All of the above

Answer : Option 1

What is the output of print(2 * 3 ** 2)?

1) 18

2) 12

3) 36

4) 9

Answer : Option 1

Which of the following is not a valid variable name in Python?

1) my_variable

2) myVariable

3) my-variable

4) _myVariable

Answer : Option 1

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 : Option 1

What is the output of print(list("abc"))?

1) ['a', 'b', 'c']

2) abc

3) Error

4) ['abc']

Answer : Option 1

How do you create a dictionary in Python?

1) myDict = {}

2) myDict = dict()

3) Both a and b

4) myDict = []

Answer : Option 1