python2中的input()只接受變量作為傳入值,非變量內容會報錯。
1 >>> user=input("Enter your name:") 2 Enter your name:Kaito 3 Traceback (most recent call last): 4 File "<stdin>", line 1, in <module> 5 File "<string>", line 1, in <module> 6 NameError: name 'Kaito' is not defined 7 >>> 8 >>> name="Kaito" 9 >>> user=input("Enter your name:") 10 Enter your name:name 11 >>> print(user) 12 Kaito
所以在python2中,我們用raw_input()來代替input()的功能來鍵入內容。
1 >>> user=raw_input("Enter your name:") 2 Enter your name:Kaito 3 >>> print(user) 4 Kaito
而python3的input()可以說是取代了python2的raw_input()。
1 >>> user=input("Enter your name:") 2 Enter your name:Kaito 3 >>> print(user) 4 Kaito
