ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print('%.3s|%5.1s|' % ('abcdef', 'xyz'))
  1. A. abc| x|
  2. B. abcdef| x|
  3. C. abc| xy|
  4. D. ab| x|

Correct answer: A. abc| x|

A precision on %s truncates the string, so .3 keeps abc. The width of 5 with precision 1 keeps only x and right-aligns it in five columns.

More Python Programming questions

Exams that ask this topic