ProgrammingModerateAccenture · Capgemini pattern

What is printed?

What is printed?
print("hello world".title(), "ab".center(6, "*"), "42".zfill(5), "-7".zfill(4))
  1. A. Hello world **ab** 00042 -007
  2. B. Hello World **ab** 00042 -007
  3. C. Hello World **ab** 00042 00-7
  4. D. Hello World ****ab 00042 -007

Correct answer: B. Hello World **ab** 00042 -007

title() capitalises the first letter of every word. center(6, "*") pads 4 characters split evenly: **ab**. zfill pads with zeros on the left to the given width, but keeps a leading sign in front, so "-7".zfill(4) is "-007", not "00-7".

More Python Programming questions

Exams that ask this topic