Subject / 929 questions

Programming MCQs

Page 37 of Programming multiple-choice questions with answers. Tap an option to check yourself.

Page 37 of 47

Question 723 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
Question 724 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 725 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
Question 728 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
Advertisement
Question 731 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
Question 733 Python

What happens if the same module is imported twice in one Python program?

Correct answer D. Its code runs only once; later imports reuse the cached module from sys.modules

Open question
Advertisement