ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 'xyz'
print(f'{x!r:>7}|{len(x):03d}|{x[::-1]:^5}|')- A. 'xyz'|03|zyx|
- B. 'xyz'|3| zyx |
- C. 'xyz'|003| zxy|
- D. 'xyz'|003| zyx |
Correct answer: D. 'xyz'|003| zyx |
!r converts to the repr with quotes, and >7 right-aligns it in seven columns. 03d zero-pads the length to width 3. Centring 'zyx' in width 5 adds one space on each side.
More Python Programming questions
- What is printed? python from itertools import chain print(list(chain.fromiterable(['ab', 'c'])), ''.join(chain([['x'], ['y', 'z']])))
- What is printed? python print(repr("it's"), repr('say "hi"'), len('x41101'), len(r'n'))
- What is printed? python print(pow(3, -1, 8)) try: print(pow(4, -1, 8)) except ValueError: print('not invertible')
- What is printed? python import math print(math.comb(100, 50) % 1000, 2100 % 9, sum(map(int, str(2100))) % 9)
- What is printed? python print(5e-324 / 2 == 0, 2e-323 > 5e-324, float('1e-400'), 5e-324 / 2 == 0.0)
- What is printed? python import math print(int(-0.5), int(-1.9), math.floor(-1.1), round(-1.5))