ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(-0.0 == 0.0, str(-0.0), repr(0.0 * -1))
  1. A. False -0.0 -0.0
  2. B. True 0.5 0.0
  3. C. True -0 0.0
  4. D. True -0.0 -0.0

Correct answer: D. True -0.0 -0.0

-0.0 is a distinct float with a sign bit, but it compares equal to 0.0. Multiplying 0.0 by -1 gives -0.0, which prints with its sign.

More Python Programming questions

Exams that ask this topic