ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(bytes.fromhex('de ad'), (255).to_bytes(2), bytes([1, 2]).hex(' '))
  1. A. b'\xde\xad' b'\xff\x00' 01 02
  2. B. b'\xde\xad' b'\xff' 0102
  3. C. b'\xde\xad' b'\x00\xff' 01 02
  4. D. b'\xde\xad' b'\x00\xff' 0102

Correct answer: C. b'\xde\xad' b'\x00\xff' 01 02

fromhex accepts spaces between byte pairs, and to_bytes defaults to big-endian since Python 3.11, so 255 becomes 00 ff. hex(' ') puts a space between the bytes.

More Python Programming questions

Exams that ask this topic