ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(len('héllo'.encode('utf-8')), len('héllo'.encode('utf-16')), len('héllo'))
  1. A. 6 12 5
  2. B. 6 10 5
  3. C. 8 12 5
  4. D. 6 12 6

Correct answer: A. 6 12 5

The é takes two bytes in UTF-8, so the text is 6 bytes. UTF-16 adds a two-byte byte-order mark and uses two bytes per code unit, giving 2 + 5 * 2 = 12. len counts code points, which is 5.

More Python Programming questions

Exams that ask this topic