0

When I type the following French character in the Python 2.X interpreter, it gives me a utf-8 byte sequence:

>>> x = 'é'
>>> x
'\xc3\xa9'

But same thing on Python 3.X results in following behavior:

>>> x = 'é'
>>> x
'é'

But it is said that default encoding for Python 3 is utf-8. Can somebody explain this behavior?

user634615
  • 647
  • 7
  • 17

1 Answers1

4

Your Python 2 example is a bytestring, your Python 3 is a unicode string. Prefix the Python 2 example with a u to get the equivalent object.

In addition, the repr of unicode strings in Python 3 changes to display the characters instead of the codepoints.

Wooble
  • 87,717
  • 12
  • 108
  • 131