ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
try:
print((300).to_bytes(1, 'big'))
except OverflowError:
print('overflow')
print((255).to_bytes(1, 'big'), int.from_bytes(b'', 'big'))- A. overflow b'\x2c' 0
- B. overflow b'\xff' 0
- C. overflow b'\xff' 1
- D. b'\xff' 0 overflow
Correct answer: B. overflow b'\xff' 0
300 needs two bytes, so to_bytes with length 1 raises OverflowError. 255 fits in one byte as 0xff, and an empty byte string converts to 0.
More Python Programming questions
- What is printed? python print(bool('0'), bool(0.0), bool(-0.0), bool(float('nan')), bool(' '))
- What is printed? python print(True & 2, True | 2, True ^ True, ~True)
- What is printed? python print(-263 // -1 == 263, abs(-263) == 263, (263) (263) > 2127, 263 263 == 2126)
- What is printed? python print(int(1e22) == 1022, int(1e23) == 1023, float(1022) == 1e22)
- What is printed? python print('{:+}'.format(-0.0), '{:+}'.format(0), '{:+.1f}'.format(-0.04), '{:+}'.format(5))
- What is printed? python print(hex(255).upper(), int('FF', 16) == 0xff, '%X' % 255 == hex(255)[2:].upper(), oct(64))