ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))
  1. A. 0.0 True -0.0 0.0
  2. B. 0.0 False -0.0 0.0
  3. C. -0.0 True 0.0 -1.0
  4. D. 0.0 True 1.0 0.0

Correct answer: A. 0.0 True -0.0 0.0

IEEE 754 zero has a sign, so str shows -0.0, yet -0.0 == 0.0 is True. Adding +0.0 to -0.0 under round-to-nearest gives +0.0.

More Python Programming questions

Exams that ask this topic