Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
print(bool([]), bool([0]), bool(0.0), bool('False'))
What is printed?
  1. A. False True True True
  2. B. False False False True
  3. C. False True False True
  4. D. True True False True

Correct answer: C. False True False True

Only empty containers and zero-valued numbers are falsy. The list [0] and the non-empty string 'False' are truthy.

More Coding Interview Problems questions

Exams that ask this topic