在编写python的时候,也会出现乱码问题,文件中未指明编码格式,会出现报错,就比如说下面的例子
print '你好,世界'
运行结果
File "C:/Users/13683/PycharmProjects/luck/com/yyf/bao/file2.py", line 1
SyntaxError: Non-ASCII character '\xe4' in file C:/Users/13683/PycharmProjects/luck/com/yyf/bao/file2
.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Process finished with exit code 1
其实解决这个问题相当简单,只需要在文章开头加一个 #coding=utf-8(如图)! 等号左右不要有空格
或者是把 #coding=utf-8替换成 # -*- coding: UTF-8 -*-