ProgrammingVery hardTCS NQT · Infosys

What is printed?

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

Correct answer: B. 3 -3 0 1

%d truncates a float toward zero, so 3.9 gives 3 and -3.9 gives -3. %.0f rounds 0.5 to the even value 0, and %i formats True as 1 because bool is a subclass of int.

More Python Programming questions

Exams that ask this topic