在Python2或Python3中打印中文字符

时间:2017-01-23 13:23:28

标签: python utf-8 chinese-locale python-3.6

最近我一直在研究Python,Py2和Py3之间存在一些差异,对于新生儿来说很难理解它们。

头上的shebang是

#!/usr/bin/env python
#-*- coding:utf-8 -*-

当我想要打印出汉字时,事情就没有了。

why they appear as the 'utf-8' format, not the original ones 即使我在每个句子中添加“.decode()”函数,它们也是一样的。

the right way to show the characters

说到Python3,我收到了错误信息。

UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-3: ordinal not in range(128)
[Finished in 0.1s with exit code 1]

0 个答案:

没有答案