python 编码问题

>>> a="中"

>>> a
'xe4xb8xad'
>>> b=a.decode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
>>> b=a.encode("utf-8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
>>> b=a.decode("utf-8")
>>> b
u'u4e2d'
>>> a=u"中"
>>> a
u'u4e2d'

怎么样才能出来中文字?

原文地址:https://www.cnblogs.com/hsdchenliyang/p/9210995.html