ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print('%5.2f|%-4d|%04x' % (3.14159, 7, 255))
  1. A. 3.14|7 |00ff
  2. B. 3.14|7 |0ff
  3. C. 3.14| 7|00fe
  4. D. 3.14|7 |ff

Correct answer: A. 3.14|7 |00ff

%5.2f gives width 5 with two decimals, so ' 3.14' keeps a leading space. %-4d left-aligns 7 in four columns, and %04x zero-pads 255 in hex to 00ff.

More Python Programming questions

Exams that ask this topic