ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print('ab'.ljust(4, '*') + '|', 'ab'.rjust(4, '*'), 'ab'.zfill(4), '12'.zfill(1))- A. ab**| **ab 0ab 12
- B. ab**| **ab 00ab 12
- C. ab**| **ab 00ab 21
- D. ab**| **ab 00ab 1
Correct answer: B. ab**| **ab 00ab 12
ljust pads on the right and rjust pads on the left, while zfill pads with zeros on the left. zfill never truncates, so '12' with width 1 stays as it is.
More Python Programming questions
- What is printed? python print('%s and %s' % ('A', 'B'), '%(x)d-%(x)05.1f' % {'x': 3}, '%%%d' % 5)
- What is printed? python print(1 / 2 + 1 // 2 + 1 % 2, 1 / 2 2 == 1, 3 1 / 2 == 3 (1 / 2))
- What is printed? python print(0x10 + 0o10 + 0b10, 10 + 0x1, 1e1 + 1, 1j 1j)
- What is printed? python print(max(-0.0, 0), min(0, -0.0), -0.0 + 0, 0 - 0.0)
- What is printed? python a = 10 b = 3 print(a / b b == a, a // b b + a % b == a, a % b / b == (a / b) % 1)
- What is printed? python print(7 % 3 2, (7 % 3) 2, -7 % 3 2, 2 3 2 % 4)