In python 2.x, raw_input()
returns a string and input()
evaluates the input in the execution context in which it is called
>>> x = input()
"hello"
>>> y = input()
x + " world"
>>> y
'hello world'
In python 3.x, input
has been scrapped and the function previously known as raw_input
is now input
. So you have to manually call compile
and than eval
if you want the old functionality.
python2.x python3.x
raw_input() --------------> input()
input() -------------------> eval(input())
In 3.x, the above session goes like this
>>> x = eval(input())
'hello'
>>> y = eval(input())
x + ' world'
>>> y
'hello world'
>>>
So you were probably getting an error at the interpretor because you weren't putting quotes around your input. This is necessary because it's evaluated. Where you getting a name error?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…