ProgrammingModerateProduct-company MCQ pattern
What is printed?
What is printed?
print(list(filter(None, [0, 1, "", "a", [], [0], None])))
- A. [0, 1, '', 'a', [], [0]]
- B. [1, 'a', [0], None]
- C. [1, 'a']
- 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
- What is printed? python def gen(): yield 1 return 5 yield 2 print(list(gen()))
- What is printed? python print("a,b,,c".split(","), len("a b c".split()))
- What is printed? python print(True + True 3, type(True + 1).name)
- What is printed? python a = [1, 2, 3, 4, 5] a[1:3] = [9] a[::2] = [0, 0] print(a)
- What is printed? python d = {} d[1] = 'a' d[1.0] = 'b' d[True] = 'c' print(d)
- What is printed? python x = [1, 2, 3] for i in x: x.remove(i) print(x)