ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
x = 3.14159
print(f"{x:08.3f}|{x:>8.2e}|{42:#x}|{'ab'!r:>6}")
  1. A. 0003.142|3.14e+00|42| 'ab'
  2. B. 0003.142|3.14e+00|0x2b| 'ab'
  3. C. 0003.142|3.14e+00|0x2a| 'ab'
  4. D. 3.142|3.14e+00|0x2a|'ab'

Correct answer: C. 0003.142|3.14e+00|0x2a| 'ab'

08.3f pads with zeros to width 8 and gives three decimals, so 0003.142. The e format gives 3.14e+00 in a width of 8. # with x adds the 0x prefix, and !r applies repr before the >6 right alignment.

More Python Programming questions

Exams that ask this topic