ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f'{1:>{3}}', '{0[1]}-{1!r}'.format('ab', 'cd'), '{0!r:>6}'.format('x'), '{:.1%}'.format(0.256))
  1. A. 1 b-'cd' 'x' 25.7%
  2. B. 2 b-cd 'x' 25.6%
  3. C. 1 b-'cd' 'x' 25.60%
  4. D. 1 b-'cd' 'x' 25.6%

Correct answer: D. 1 b-'cd' 'x' 25.6%

{0[1]} indexes the second character of the first argument, while !r applies repr to the second argument. The :>6 spec right-aligns the repr 'x' in six columns, and the percent format multiplies by 100 with one decimal.

More Python Programming questions

Exams that ask this topic