ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print((255).to_bytes(2, 'big'), (1).to_bytes(3, 'little'))
  1. A. b'\xff\x00' b'\x00\x00\x01'
  2. B. b'\x00\xff' b'\x00\x00\x01'
  3. C. b'\xff' b'\x01\x00\x00'
  4. D. b'\x00\xff' b'\x01\x00\x00'

Correct answer: D. b'\x00\xff' b'\x01\x00\x00'

255 in two bytes big-endian is 00 FF. 1 in three bytes little-endian puts the 1 in the first byte, followed by two zero bytes.

More Python Programming questions

Exams that ask this topic