ProgrammingVery hardCAT · MBA placement
What is printed?
What is printed?
print(b'abc'[0], bytes([65, 66]), bytes.fromhex('41 42'), len(b'a' * 2 + b'\x00'))- A. 97 b'AB' b'AB' 3
- B. 97 b'AB' b'AB' 2
- C. 'a' b'AB' b'AB' 3
- D. 97 AB AB 3
Correct answer: A. 97 b'AB' b'AB' 3
Indexing bytes gives an integer, so b'abc'[0] is 97. bytes.fromhex accepts spaces between byte pairs, and the length counts the two a bytes plus the null byte.
More Python Programming questions
- What is printed? python print(sorted(['b', 'A', 'c', 'B'], key=str.casefold, reverse=True))
- What is printed? python try: print(sorted([3, None, 1])) except TypeError: print('cannot compare')
- What is printed? python print('%(a)s-%(b)05.1f' % {'a': 'x', 'b': 3.14159})
- What is printed? python s = 'Ünïcödé' print(len(s), len(s.encode()), s.upper() == 'ÜNÏCÖDÉ')
- What is printed? python print(int('10', 2), int('0o17', 0), int('17', 8), int('0xff', 16))
- What is printed? python x = 0xDEAD print(x >> 8 & 0xFF, (x >> 8) & 0xF, hex(x & -x))