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 <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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章