ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
s = 'abc'
print(s.center(7, '*'), s.zfill(5), '-'.join(['x']), s.ljust(2, '.'))
  1. A. **abc** 00abc x abc
  2. B. **abc** abc00 x abc
  3. C. **abc** 00abc x ab.
  4. D. **abc** 00abc xy abc

Correct answer: A. **abc** 00abc x abc

center(7, '*') pads both sides evenly, with two stars on the left and two on the right. zfill pads with zeros on the left. ljust never shortens a string, so 'abc' stays as it is.

More Python Programming questions

Exams that ask this topic