ProgrammingModerateAccenture · Capgemini pattern
What is printed?
What is printed?
print("hello world".title(), "ab".center(6, "*"), "42".zfill(5), "-7".zfill(4))- A. Hello world **ab** 00042 -007
- B. Hello World **ab** 00042 -007
- C. Hello World **ab** 00042 00-7
- 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
- What is printed? python d = dict(zip("abc", range(3))) d.update({"b": 9, "d": 1}) print(list(d.items())[1], sum(d.values()), len(d))
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a - b, b - a, len(a | b), a & b == {4, 3})
- What is printed? python print(" ".join(i ch for i, ch in enumerate("xyz", 1)), list(enumerate("ab"))[-1])
- What is printed? python nums = list(range(10)) print(nums[8:2:-2], nums[-3:], nums[2:8:-1])
- What is printed? python print(min([3, -4, 2], key=lambda v: v v), max({"a": 3, "b": 1}), max("abc", "b", key=len))
- What is printed? python class Box: def len(self): return 0 b = Box() print(bool(b), "yes" if b else "no", len([b, b]))