PCEP-30-02 · Question #6
What is the expected output of the following code? ``python data = [1, 2, 3, None, (), [], [] ] print(len(data)) ``
The correct answer is B. 6. Note on the question as written: The list as shown - [1, 2, 3, None, (), [], []] - actually contains 7 elements (the trailing [] appears twice), so running this exact code would print 7, not 6. This appears to be a typo in the question; the intended list was likely [1, 2, 3…
Question
data = [1, 2, 3, None, (), [], [] ]
print(len(data))
Options
- A4
- B6
- C5
- D3
How the community answered
(54 responses)- A6% (3)
- B83% (45)
- C9% (5)
- D2% (1)
Explanation
Note on the question as written: The list as shown - [1, 2, 3, None, (), [], []] - actually contains 7 elements (the trailing [] appears twice), so running this exact code would print 7, not 6. This appears to be a typo in the question; the intended list was likely [1, 2, 3, None, (), []] with 6 elements.
Explaining the intended question (6-element list):
len() counts the number of top-level items in a list, regardless of their value or "truthiness" - None, the empty tuple (), and the empty list [] are all fully valid list elements and each count as one. This is the core insight: option B (6) is correct because the list contains exactly 6 objects separated by commas.
The distractors exploit a common misconception: A (4) and D (3) suggest that "falsy" values like None, (), and [] are somehow ignored - they are not. C (5) likely comes from miscounting, perhaps collapsing () and [] as "the same thing."
Memory tip: len() counts containers, not contents - an empty box is still a box. If you can type it between commas in a list literal, len() counts it.
Community Discussion
No community discussion yet for this question.