ProgrammingHardInfosys HackWithInfy · TCS CodeVita

What does the following Python 3 code print? print(list(filter(lambda x: x % 2 == 0, range(10))))

  1. A. [0, 2, 4, 6, 8]
  2. B. [1, 3, 5, 7, 9]
  3. C. [2, 4, 6, 8]
  4. D. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Correct answer: A. [0, 2, 4, 6, 8]

filter keeps only the elements for which the predicate is True; even numbers in range(10) are 0,2,4,6,8.

More Python Programming questions

Exams that ask this topic