OA. free
Free
MathWorks Core Computer Science Core Computer Science Medium

What is the expected output of evaluating the following Python expression?

MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.

What is the expected output of evaluating the following Python expression?

all([2, 56, 4, 0, 5, 12])
Choose one option.
Show answer & explanation
Answer: A. False

The all() function returns True only if all elements in the iterable are truthy. In this list, the integer 0 is falsy, so all() immediately returns False. The remaining elements (2, 56, 4, 5, 12) are truthy, but the presence of even one falsy value causes the entire expression to evaluate to False.

Step-by-step Derivation:
Step-by-step evaluation of all([2, 56, 4, 0, 5, 12]):

  1. all() checks each element for truthiness: 2 (truthy), 56 (truthy), 4 (truthy), 0 (falsy) ← stops here
  2. Since 0 is falsy and all() requires ALL elements to be truthy, it returns False
  3. Output: False (a boolean value, not the integer 0)

Note: Option D (0) is incorrect because all() always returns a boolean (True or False), never an integer.