ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print('42'.zfill(5), '-42'.zfill(5), 'ab'.center(6, '*'), 'x'.ljust(3, '.') + '|')- A. 00042 -0043 **ab** x..|
- B. 00042 -0042 **ab** x..|
- C. 00042 +0042 **ab** z..|
- 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
- What is printed? python print(10 / 2, 10 // 2, 7 / 7, 2 3 + 4)
- What is printed? python print('abc'.index('c'), 'abcabc'.rfind('b'), 'abc'.find('d'), len('abc'[1:]))
- What is printed? python print(sorted('bca'), ''.join(sorted('bca', reverse=True)), sorted([3, 1, 2], reverse=True)[0], list(reversed('ab')))
- What is printed? python print(int('12') + int('3'), '12' + '3', 12 + 3 == int('15'), 'x')
- What is printed? python s = 'Python' print(s[0], s[-1], s[1:4], s[::2])
- What is printed? python print(len([1, 2, 3] 2), [1, 2] + [3], [0] 0, [[0] 2] 2 == [[0, 0], [0, 0]])