ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
print(list(filter(None, [0, 1, "", "a", [], [0], None])))
  1. A. [0, 1, '', 'a', [], [0]]
  2. B. [1, 'a', [0], None]
  3. C. [1, 'a']
  4. D. [1, 'a', [0]]

Correct answer: D. [1, 'a', [0]]

filter(None, ...) keeps only truthy items. 0, "", [] and None are falsy. [0] is a non-empty list, so it is truthy even though it contains a zero.

More Python Programming questions

Exams that ask this topic