ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print('42'.zfill(5), '-42'.zfill(5), 'ab'.center(6, '*'), 'x'.ljust(3, '.') + '|')
  1. A. 00042 -0043 **ab** x..|
  2. B. 00042 -0042 **ab** x..|
  3. C. 00042 +0042 **ab** z..|
  4. D. 00042 -0042 **ab** y..|

Correct answer: B. 00042 -0042 **ab** x..|

zfill pads on the left and keeps the sign in front of the zeros, while center puts the fill character on both sides. ljust pads on the right, so x gets two dots.

More Python Programming questions

Exams that ask this topic