ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(list(filter(None, [0, '', [], [0], None])))
- A. [0, '', [], [0], None]
- B. [[0]]
- C. []
- D. [[0], None]
Correct answer: B. [[0]]
filter with None keeps only the truthy items. [0] is a non-empty list and so is truthy, while 0, '', [] and None are falsy.
More Python Programming questions
- What is printed? python print([i for i in range(10) if i % 3 == 0][::-2])
- What is printed? python print(set('mississippi') == set('misp'), len(set('mississippi')))
- What is printed? python print(0.1 3 == 0.3, abs(0.1 3 - 0.3) < 1e-9)
- What is printed? python a = [1, 2, 3] print(a[3:], a[1:10], a[-10:1])
- What is printed? python print(len(bytes('é', 'utf-8')), len('é'))
- What is printed? python print(float('inf') > 10308, -float('inf') < -10308)