ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f'{3.14159:.2}', f'{"abc":.2}', f'{0.5:.0%}')
  1. A. 3.1 ab 50%
  2. B. 3.14 ab 50%
  3. C. 3.1 abc 50%
  4. D. 3.1 ab 0.5

Correct answer: A. 3.1 ab 50%

For a float, .2 means two significant digits, so 3.14159 gives 3.1. For a string it truncates to two characters, and the percent type multiplies by 100.

More Python Programming questions

Exams that ask this topic