python2中的input()只接受变量作为传入值,非变量内容会报错。
>>> user=input("Enter your name:")
Enter your name:Kaito
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'Kaito' is not defined
>>>
>>> name="Kaito"
>>> user=input("Enter your name:")
Enter your name:name
>>> print(user)
Kaito
所以在python2中,我们用raw_input()来代替input()的功能来键入内容。
>>> user=raw_input("Enter your name:")
Enter your name:Kaito
>>> print(user)
Kaito
而python3的input()可以说是取代了python2的raw_input()。
>>> user=input("Enter your name:")
Enter your name:Kaito
>>> print(user)
Kaito