Programming · Flashcard

What does 0.1 + 0.2 == 0.3 evaluate to?

  • AFalse — the sum is 0.30000000000000004, not 0.3
  • BTrue — Python rounds float results before comparing
  • CFalse — Python compares floats by identity, not value
  • DTrue — decimal literals are stored exactly as written

Why this is the answer

Binary floating point cannot represent 0.1 or 0.2 exactly, so their sum is 0.30000000000000004 and the comparison is False. No rounding is applied before ==, which does compare values (identity is is), and decimal literals are converted to the nearest binary double — use math.isclose() or the decimal module when exactness matters.

Official docs
Study in Gnoseed →