Learn Python MCQs

Prepare Python MCQs (Multiple choice Questions) for exam and job interviews.

Which of the following keywords is used to define an inner function?

1) inner

2) def

3) function

4) None of the above

Answer : Option 1

How do you create a generator in Python?

1) yield

2) return

3) function

4) def

Answer : Option 1

What is the output of print("Python".count("P"))?

1) 1

2) 0

3) Error

4) 2

Answer : Option 1

Which of the following statements is used to end a loop in Python?

1) break

2) continue

3) exit

4) stop

Answer : Option 1

What is the output of print({1, 2, 3}.add(2))?

1) None

2) Error

3) {1, 2, 3}

4) {1, 2, 3, 2}

Answer : Option 1

How do you get the keys of a dictionary in Python?

1) dict.keys()

2) dict.get_keys()

3) keys(dict)

4) None of the above

Answer : Option 1

What is the output of print(type((1, 2)))?

1)

2)

3) tuple

4) Error

Answer : Option 1

How do you create a nested dictionary in Python?

1) myDict = { "key": { "subkey": "value" } }

2) myDict = { "key": "value" }

3) Both a and b

4) None of the above

Answer : Option 1

What is the output of print(1 in [1, 2, 3])?

1) True

2) False

3) None

4) Error

Answer : Option 1

How do you create a read-only property in Python?

1) @property def myProp(self):

2) def myProp(self):

3) @readonly def myProp(self):

4) None of the above

Answer : Option 1