ProgrammingModerateGATE CS · Product-company placement

What is printed?

What is printed?
a = 1e308
b = a * 10
print(b, -b, b - b if False else 0, b > a, b == float('inf'))
  1. A. inf -inf 0 False True
  2. B. inf inf 1 True True
  3. C. nan -inf 0 True True
  4. D. inf -inf 0 True True

Correct answer: D. inf -inf 0 True True

Multiplying a large finite float by 10 overflows to inf, and negating it gives -inf. Infinity compares greater than any finite float, so both comparisons are True.

More Python Programming questions

Exams that ask this topic