ProgrammingHardAccenture · Cognizant · Python
What does the following Python 3 code print? print(bool([]), bool({}), bool(()), bool(0.0), bool("0"))
- A. True True True False True
- B. False False False False True
- C. False False False False False
- D. False False False True True
Correct answer: B. False False False False True
Empty containers and 0.0 are falsy, but the non-empty string "0" is truthy regardless of its text content.
More Python Programming questions
- What does the following Python 3 code print? print([] == False, [] is False)
- What does the following Python 3 code print? x = [1, 2, 3] y = [1, 2, 3] print(x == y, x is y)
- What does the following Python 3 code print? print(2 10, 2 0.5, 10 // 3, -10 // 3, 10 % 3, -10 % 3)
- What does the following Python 3 code print? print(id([1, 2]) == id([1, 2]))
- What does the following Python 3 code print? try: a = (1, 2, 3) a[0] = 9 except TypeError: print("TypeError")
- What does the following Python 3 code print? try: d = {} print(d["missing"]) except KeyError: print("KeyError")