ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(len(f'{3.5:>8.2f}'), f'{-3.5:08.1f}', f'{12:#06x}', f'{7:+05d}')
  1. A. 8 -0003.5 0x000c +0007
  2. B. 8 -00003.5 0x0c +0007
  3. C. 8 -00003.5 0x000c +0007
  4. D. 7 -00003.5 0x000c +0007

Correct answer: C. 8 -00003.5 0x000c +0007

The width 8 spec pads 3.50 to eight characters. With zero padding the sign comes first, and # with x keeps the 0x prefix inside the six-character width. The + with zero padding gives +0007.

More Python Programming questions

Exams that ask this topic