ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(len('%d' % -0), '%d' % -0.0, '%.1f' % -0.0)
  1. A. 1 1 -0.0
  2. B. 2 0 -0.0
  3. C. 1 0 0.5
  4. D. 1 0 -0.0

Correct answer: D. 1 0 -0.0

The integer -0 is just 0, so %d prints a single character. %d truncates -0.0 to the int 0, but %.1f keeps the sign bit of the float and prints -0.0.

More Python Programming questions

Exams that ask this topic