ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print((255).to_bytes(2, 'big'), (1).to_bytes(3, 'little'))
- A. b'\xff\x00' b'\x00\x00\x01'
- B. b'\x00\xff' b'\x00\x00\x01'
- C. b'\xff' b'\x01\x00\x00'
- 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
- What is printed? python print(sorted(range(10), key=lambda x: (x % 3, -x))[:4])
- What is printed? python print(''.join(sorted('banana', reverse=True)), len(set('abcABC'.lower())), 'ABC'.isupper())
- Which implementation of "count how many times each character appears in s" is the best choice in Python when len(s) = 2 10^5?
- What is printed? python from itertools import accumulate print(list(accumulate([1, 2, 3], initial=0)), next(iter(sorted({3, 1, 2}))))
- What is printed? python st = [] for t in '2 1 + 3 '.split(): if t.isdigit(): st.append(int(t)) else: b = st.pop() a = st.pop() st.append(a…
- What is printed? python a = [-2, 1, -3, 4, -1, 2, 1, -5, 4] best = cur = a[0] for x in a[1:]: cur = max(x, cur + x) best = max(best, cur)…