ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(bytes('é', 'utf-8'), 'é'.encode('latin-1'), len('é'.encode('latin-1')) == len('é'.encode('utf-8')))
  1. A. b'\xc3\xa9' b'\xc3\xa9' False
  2. B. b'\xc3\xa9' b'\xe9' False
  3. C. b'\xe9' b'\xc3\xa9' True
  4. D. b'\xc3\xa9' b'\xe9' True

Correct answer: B. b'\xc3\xa9' b'\xe9' False

In UTF-8 é is the two bytes c3 a9, while Latin-1 stores it as the single byte e9. The byte counts differ, so the final comparison is False.

More Python Programming questions

Exams that ask this topic