HappyPy
HappyPy

Reputation: 10697

why are strings encoded in utf-8 if the default encoding is ascii? - python

In python, when I import sys and type:

>>> sys.getdefaultencoding()
>>> 'ascii'

why is this string automatically encoded as UTF-8?

>>> a = 'ö'
>>> a
>>> '\xc3\xb6'

Upvotes: 0

Views: 177

Answers (1)

hobbs
hobbs

Reputation: 240729

Because the input you provided to python was

 a        =       '   ö       '
\x61\x20\x3d\x20\x27\xc3\xb6\x27

You told a to contain the byte sequence "\xc3\xb6" by putting those two bytes between the quotes in your console input, and so it does.

Upvotes: 1

Related Questions