ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(float('0.1') == 0.1, float(' 0.1 ') == 0.1, 0.1 == float(str(0.1)), 1e23 == 10**23)
  1. A. True True False True
  2. B. False True True False
  3. C. True False True False
  4. D. True True True False

Correct answer: D. True True True False

float() parses the decimal text to the same nearest double as the literal, so the first three comparisons are True. The float 1e23 is not exactly 10**23, so the exact int comparison is False.

More Python Programming questions

Exams that ask this topic