ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(f'{12.0:g}', f'{12.5:g}', f'{0.00001234:g}', f'{123456789:g}', f'{1.5e300:g}')
  1. A. 12 12.5 1.234e-05 1.23457e+08 1.5e+300
  2. B. 12.0 12.5 1.234e-05 1.23457e+08 1.5e+300
  3. C. 12 12.5 0.00001234 123456789 1.5e+300
  4. D. 12 12.5 1.234e-05 1.23457e+08 1500e+297

Correct answer: A. 12 12.5 1.234e-05 1.23457e+08 1.5e+300

The g format drops trailing zeros, so 12.0 shows as 12. Integers passed to g are converted to float first, so 123456789 keeps six significant digits as 1.23457e+08.

More Python Programming questions

Exams that ask this topic