Python2.7使用'input'读取输入文本出现NameError错误
原博客:https://blog.csdn.net/dfq12345/article/details/78074749在Python2.7中内置函数input()会将输入数据当成指令,从键盘中输入数据应该使用raw_input()在Python3中input()函数用于从键盘中读取数据1 #!/usr/bin/python2 # -*- coding: utf-8 -*-...
·
原博客:https://blog.csdn.net/dfq12345/article/details/78074749
在Python2.7中内置函数input()会将输入数据当成指令,从键盘中输入数据应该使用raw_input()
在Python3中input()函数用于从键盘中读取数据
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # 使用 input 会出现NameError
5 message = input("Tell me something, and I will repeat it back to you!\n>")
6 # message = raw_input("Tell me something, and I will repeat it back to you!\n>")
7 print(message)
Tell me something, and I will repeat it back to you!
>Hello
Traceback (most recent call last):
File "./abc.py", line 5, in <module>
message = input("Tell me something, and I will repeat it back to you!\n>")
File "<string>", line 1, in <module>
NameError: name 'Hello' is not defined
更多推荐
已为社区贡献1条内容
所有评论(0)