ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('x'.center(4, '-') + '|', '7'.zfill(3) + '|', '-7'.zfill(4))
  1. A. -x--| 007| -007
  2. B. --x-| 008| -007
  3. C. -x--| 007| -0007
  4. D. -x--| 00| -007

Correct answer: A. -x--| 007| -007

center puts the extra padding character on the left when the padding is odd, giving -x--. zfill pads with zeros after any sign, so -7 becomes -007.

More Python Programming questions

Exams that ask this topic