input會假設用戶輸入的是合法的Python表達式
raw_input會把所有的輸入當作原始數據,然后將其放入字符串中。
在最新的版本之中,input可以直接使用,替代了raw_input.
在2.7的版本中
>>> input('Enter you age: ')
Enter you age: kebi input假設你輸入的是字符串,但是字符串需要帶引號啊
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'kebi' is not defined
直接輸入數字會報錯。
加上引號就可以了
>>> input('Enter you age: ')
Enter you age: 'kebi'
'kebi' 加上引號就沒事了
>>> raw_input('Enter you age: ')
Enter you age: kebi 使用raw_input就不會存在這個問題了
'kebi'
在3.6的版本中
>>> raw_input('you name:') raw_input直接就不存在了,統一使用input
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'raw_input' is not defined
>>> input('you name:')
you name:kebi
'kebi'
總結:不得不說這是一次進步。