ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: B. 0 0 True -0.0 -0.0

Integers have no negative zero, so str(-0) and int('-0') are both 0. Floats keep the sign bit, so -0.0 == 0 is True, while str(-0.0) and 0 * -1.0 both show -0.0.

More Python Programming questions

Exams that ask this topic