ProgrammingHardIBM · Deloitte · Product Company SDE

What does the following Python 3 code print? print("%d-%s-%.2f" % (5, "hi", 3.14159))

  1. A. %d-hi-3.14
  2. B. 5-hi-3.141
  3. C. 5-hi-3.1
  4. D. 5-hi-3.14

Correct answer: D. 5-hi-3.14

Old-style % formatting substitutes each specifier in order: %d->5, %s->hi, %.2f rounds 3.14159 to 3.14.

More Python Programming questions

Exams that ask this topic