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

在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 
    message = input("Tell me something, and I will repeat it back to you!\n>")
  File "", line 1, in 
NameError: name 'Hello' is not defined

你可能感兴趣的:(Python使用'input'读取输入文本出现NameError错误)