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'))
  1. A. 97 b'AB' b'AB' 3
  2. B. 97 b'AB' b'AB' 2
  3. C. 'a' b'AB' b'AB' 3
  4. 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

Exams that ask this topic