ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
x = 'xyz'
print(f'{x!r:>7}|{len(x):03d}|{x[::-1]:^5}|')
  1. A. 'xyz'|03|zyx|
  2. B. 'xyz'|3| zyx |
  3. C. 'xyz'|003| zxy|
  4. 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

Exams that ask this topic