# 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
即支持中文编写
网友评论