ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(len('é'.encode('utf-8')), len('é'.encode('utf-16-le')), len('a€'.encode()), b'\xc3\xa9'.decode())
  1. A. 2 2 3 é
  2. B. 1 2 4 é
  3. C. 2 4 4 é
  4. D. 2 2 4 é

Correct answer: D. 2 2 4 é

é takes two bytes in UTF-8 and two in UTF-16 little-endian. The euro sign takes three bytes in UTF-8, so 'a€' takes one plus three, and the byte pair c3 a9 decodes back to é.

More Python Programming questions

Exams that ask this topic