ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(f'{-5:+}', f'{5:+}', f'{3.0:g}', f'{1e6:g}', f'{1e-5:g}', f'{123456789.0:g}')
  1. A. -5 +5 3.0 1000000 0.00001 123456789.0
  2. B. -5 +5 3 1e+06 1e-05 1.2346e+08
  3. C. -5 +5 3 1e+06 1e-05 1.23457e+08
  4. D. -5 +5 3 1e+6 1e-5 1.23457e+8

Correct answer: C. -5 +5 3 1e+06 1e-05 1.23457e+08

The g format drops trailing zeros and switches to scientific notation once the exponent reaches the precision (6 significant digits by default). The + sign flag shows a sign for positive numbers too.

More Python Programming questions

Exams that ask this topic