ProgrammingVery hardTCS NQT · Accenture

What is printed?

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

Correct answer: A. True -0.0 -0.0 -0.0

Negative zero compares equal to zero, and str() of a negative zero float keeps the minus sign. Multiplying a float by -1 gives -0.0 when the other factor is zero.

More Python Programming questions

Exams that ask this topic