ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
x = []
print(bool(x), bool([0]), bool({}), bool({0: 0}))- A. False True False True
- B. False False False False
- C. True True True True
- D. False True True True
Correct answer: A. False True False True
An empty list/dict is falsy regardless of content type (empty [] and {} are both False). A list containing [0] is non-empty, hence truthy, even though its only element (0) is itself falsy. A dict with one entry {0:0} is also non-empty, hence truthy.
More Python Programming questions
- What is printed? python import itertools print(list(itertools.islice(itertools.count(5, 2), 4)))
- What is printed? python import itertools print(list(itertools.chain([1, 2], [3, 4]))) print(list(itertools.chain.fromiterable([[1, 2], [3…
- What is printed? python import itertools print(list(itertools.combinations([1, 2, 3, 4], 2)))
- What is printed? python import itertools print(list(itertools.accumulate([1, 2, 3, 4]))) print(list(itertools.accumulate([1, 2, 3, 4]…
- What is printed? python print(list(zip([1, 2, 3], [4, 5], [6, 7, 8, 9]))) from itertools import ziplongest print(list(ziplongest([1, 2…
- What is printed? python print(list(enumerate(["a", "b", "c"], start=5)))