ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(bytes.fromhex('de ad'), (255).to_bytes(2), bytes([1, 2]).hex(' '))- A. b'\xde\xad' b'\xff\x00' 01 02
- B. b'\xde\xad' b'\xff' 0102
- C. b'\xde\xad' b'\x00\xff' 01 02
- 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
- What is printed? python print(round(1.5, 0), round(-2.5), round(2.5, 0) == 2, round(0.5, 0) == 0)
- What is printed? python from math import floor, ceil, trunc print(floor(-0.5), ceil(-0.5), trunc(-0.5), floor(2))
- What is printed? python print(sorted([3, 1, 2], key=lambda x: -x)[0], sorted('bca', key=lambda c: c > 'a'))
- What is printed? python print(int('10', 36) == 36, int('Z', 36), int('z', 36) + 1, int('10', 2) == 2)
- What is printed? python x = [1, 2, 3] print(x.pop(), x.pop(0), x, x.insert(0, 9) or x)
- What is printed? python print(max(map(len, ['a', 'bbb', 'cc'])), min(len(s) for s in ['a', 'bbb']), sum(len(s) for s in ['ab', 'c']))