ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('%.3s' % 'abcdef' + '|' + '%-4d|' % 7 + '%04.1f' % 2.25)
  1. A. abc|7 |02.2
  2. B. abc|7 |2.2
  3. C. abc|7 |02.3
  4. D. abd|7 |02.2

Correct answer: A. abc|7 |02.2

%.3s keeps the first three characters. %-4d left-aligns 7 in four columns, and 2.25 is an exact tie that rounds to even 2.2, padded to four characters with a leading zero.

More Python Programming questions

Exams that ask this topic