ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
x = []
print(bool(x), bool([0]), bool({}), bool({0: 0}))
  1. A. False True False True
  2. B. False False False False
  3. C. True True True True
  4. 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

Exams that ask this topic