ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(format(255, '08b'), format(255, '#x'), '{:>5}|{:<3}|'.format(42, 7))
  1. A. 11111111 0xfe 42|7 |
  2. B. 11111111 0xff 42|7 |
  3. C. 11111111 0b11111111 42|7 |
  4. D. 11111111 0xff 7|42 |

Correct answer: B. 11111111 0xff 42|7 |

The 08b spec pads a binary string to 8 digits, and # with x adds the 0x prefix. Width 5 right-aligns 42 with three leading spaces, and 7 is left-aligned in width 3.

More Python Programming questions

Exams that ask this topic