Topic / 88 questions

Python MCQs

Page 2 of Python multiple-choice questions with answers. Tap an option to check yourself.

Page 2 of 5

Question 21 Python

What does the pass statement do in Python?

Correct answer D. Nothing; it is a placeholder where a statement is syntactically required

Open question
Advertisement
Advertisement
Question 33 Python

When does the else block of a Python while loop execute?

Correct answer D. When the loop condition becomes false without a break being executed

Open question
Question 34 Python

What is the recommended way to give a function parameter a fresh empty list as its default on every call?

Correct answer D. Use items=None and create the list inside the function when items is None

Open question
Advertisement
Question 37 Python

What is the purpose of the nonlocal statement in a nested function?

Correct answer B. It lets the inner function rebind a variable in the nearest enclosing function scope

Open question
Question 40 Python

Why is the block if __name__ == “__main__”: commonly used in a Python module?

Correct answer A. So the code inside runs when the file is executed directly but not when it is imported

Open question