ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print('ab'.ljust(4, '*') + '|', 'ab'.rjust(4, '*'), 'ab'.zfill(4), '12'.zfill(1))
  1. A. ab**| **ab 0ab 12
  2. B. ab**| **ab 00ab 12
  3. C. ab**| **ab 00ab 21
  4. D. ab**| **ab 00ab 1

Correct answer: B. ab**| **ab 00ab 12

ljust pads on the right and rjust pads on the left, while zfill pads with zeros on the left. zfill never truncates, so '12' with width 1 stays as it is.

More Python Programming questions

Exams that ask this topic