Python使用'input'读取输入文本出现NameError错误

来源:互联网 发布:想做淘宝客服兼职 编辑:程序博客网 时间:2024/06/04 07:41

在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!>HelloTraceback (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
原创粉丝点击