ProgrammingHardTCS CodeVita · GATE CS · Advanced

What does the following Python 3 code print? print(0.1 + 0.2 == 0.3)

  1. A. Error
  2. B. False
  3. C. True
  4. 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

Exams that ask this topic