关于 Python SyntaxError 的错误

晚上学习 Python,下面一段代码

item = 1 item2 = 2 item3 = 3 total = item + item2 + \ item3 print(total) text = """这是Python, 我正在学习Python 哈哈哈""" print(text)

Terminal 报错如下错误:

SyntaxError: Non-ASCII character '\xe8' in file helloworld.py on line 12, but no encoding declared;

开始以为是首航缩进的问题才报的错误,但是改了缩进之后依旧报错,后 Google 得知Python在默认状态下不支持源文件中的编码

解决方案:

可以在*.py 即文件的首行添加如下注释代码即可

一: # coding=utf-8

或者:

二: -*- coding: utf-8 -*-

猜你喜欢

转载自www.cnblogs.com/licript/p/10022700.html