在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