ProgrammingHardTCS CodeVita · GATE CS · Advanced
What does the following Python 3 code print? print(0.1 + 0.2 == 0.3)
- A. Error
- B. False
- C. True
- D. None
Correct answer: B. False
0.1 and 0.2 cannot be represented exactly in binary floating point, so their sum is slightly more than 0.3, making the equality False.
More Python Programming questions
- What does the following Python 3 code print? print(bool([]), bool({}), bool(()), bool(0.0), bool("0"))
- 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")