ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(len('ab' * 3 * 0 + 'c'), ('%5.2f' % 3.14159).strip(), '%-5s|' % 'ab', '%05d' % -42)
  1. A. 1 3.14 a| -0042
  2. B. 1 3.14 ab |-42
  3. C. 3 3.14 ab | -0042
  4. D. 1 3.14 ab | -0042

Correct answer: D. 1 3.14 ab | -0042

'ab' * 3 * 0 is the empty string, so the length is 1. %-5s left-aligns 'ab' in five columns, and %05d zero-pads -42 to width five with the sign first, giving -0042.

More Python Programming questions

Exams that ask this topic