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
时间: 2024-11-05 00:30:34