ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: D. 5 6 b'\xc3\xa9'

The string has five code points, but the é in UTF-8 takes two bytes, so the encoded length is 6. The bytes of é are C3 and A9.

More Python Programming questions

Exams that ask this topic