import sys reload(sys) sys.setdefaultencoding("utf-8") print "Who do you think I am?" you = input() print "Oh, yes! I am a"print you
输入adasdasd报错如下
C:\Python27\python.exe H:/pycharmWorkSpace/test11.py Who do you think I am? asfasf Traceback (most recent call last): File "H:/pycharmWorkSpace/test11.py", line 5, in <module> you = input() File "<string>", line 1, in <module> NameError: name 'asfasf' is not defined Process finished with exit code 1
这是py2.7,py2.7会把输入当成变量名字,
吧adasdasd名字的变量赋值给you,找不到adasdasd变量,就报错
解决方法一:
C:\Python27\python.exe H:/pycharmWorkSpace/test11.py Who do you think I am? 'asfasf' Oh, yes! I am a asfasf Process finished with exit code 0
输入带''
解决方法二
input()改成row_input()
print "Who do you think I am?" you = raw_input() print "Oh, yes! I am a" print you
py NameError: name 'asfasf' is not defined
最新推荐文章于 2023-10-09 10:31:28 发布