美文网首页
# coding=utf-8@python

# coding=utf-8@python

作者: 未雨绸缪2099 | 来源:发表于2018-05-19 11:21 被阅读0次

# ask for their age

myAge = input()
print('You will be ' + str( int(myAge) +1 ) + ' in a year.') #str表示string

运行时报错:

SyntaxError: Non-ASCII character '\xe8' in file p1.py on line 14, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

解释:
Python在默认状态下不支持源文件中的编码

解决:
1.全英文编写,不用中文

# ask for their age

myAge = input()
print('You will be ' + str( int(myAge) +1 ) + ' in a year.') #str means string

2.在文件头部添加如下注释码: # coding=<encoding name> 例如,可添加# coding=utf-8
或者 # encoding: utf-8
即支持中文编写

相关文章

网友评论

      本文标题:# coding=utf-8@python

      本文链接:https://www.haomeiwen.com/subject/bcuodftx.html