ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print(list('hi'.encode('utf-16-le')), len('hi'.encode('utf-32')))
  1. A. [104, 0, 105, 0] 8
  2. B. [104, 105] 12
  3. C. [0, 104, 0, 105] 12
  4. D. [104, 0, 105, 0] 12

Correct answer: D. [104, 0, 105, 0] 12

UTF-16 little-endian stores each ASCII letter as its byte followed by a zero byte. UTF-32 adds a four-byte byte-order mark and four bytes per character, so 4 + 2 * 4 = 12.

More Python Programming questions

Exams that ask this topic