编程语言
首页 > 编程语言> > python字符编码乱码问题(\xe4\xb8\xad\xe6\x96\x87)

python字符编码乱码问题(\xe4\xb8\xad\xe6\x96\x87)

作者:互联网

python默认编码格式为ASCII码,不能使用非英文字符
s = '''大湘菜'''
print(s)

结果会报错:

SyntaxError: Non-UTF-8 code starting with '\xb4' in file D:\Pycharm\pythonProject\main.py on line 1, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details

只需要在最开始添加:

#coding=UTF-8

或:

# -*- coding:UTF-8 -*-

即可

 

标签:编码,x87,xb8,字符,python,coding,乱码,UTF
来源: https://www.cnblogs.com/daxiangcai/p/16181602.html