input函数总是假设用户输入的事合法的python表达式:
>>> input('hello:')
hello:1
1
>>> input('hello:')
hello:hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
>>> input('hello:')
hello:"hello"
'hello'
>>> input('hello:')
hello:1+2
3
raw_input会把所有的输入都当作原始数据,然后将其存放在字符串中:
>>> f = input("hello:")
hello:"hello"
>>> raw_input("hello:")
hello:1
'1'
>>> raw_input("hello:")
hello:hello
'hello'
>>> raw_input("hello:")
hello:1+2
'1+2'