ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f"{12:>{5}}|{3.14159:.{2}f}|{'ab':*^6}")
  1. A. 12|3.1|**ab**
  2. B. 12|3.14|**ba**
  3. C. 12|3.14|**ab**
  4. D. 12|3.14|*a b*

Correct answer: C. 12|3.14|**ab**

A nested replacement field such as {5} inside the spec supplies the width, so 12 is right-aligned in five columns. The precision {2} gives two decimals, and * fills the centred 'ab' in a width of six.

More Python Programming questions

Exams that ask this topic