ProgrammingHardInfosys HackWithInfy · TCS CodeVita
What does the following Python 3 code print? print(list(filter(lambda x: x % 2 == 0, range(10))))
- A. [0, 2, 4, 6, 8]
- B. [1, 3, 5, 7, 9]
- C. [2, 4, 6, 8]
- 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
- What is printed? python print(type(10 / 5))
- Which of these built-in Python types is immutable?
- What is printed? python s = "placement" print(s[2:5])
- What is printed? python print(len({1, 2, 2, 3, 3, 3}))
- Which keyword turns an ordinary Python function into a generator function?
- What is printed? python x = [1, 2, 3] x.append([4, 5]) print(len(x))