varname = input("what is your name?: ")
print ("Hello", varname)
有人知道为什么这不起作用吗?只需打印
Traceback (most recent call last):
File "C:/Users/sfawcett/Desktop/python.py", line 1, in <module>
varname = input("what is your name?: ")
File "<string>", line 1, in <module>
NameError: name 'Lewis' is not defined
答案 0 :(得分:2)
input()
评估字符串。要获得原始值,您应该使用raw_input()
答案 1 :(得分:0)
在python3中: -
In [4]: varname = input("what is your name?: ")
what is your name?: lewis
In [5]: print ("Hello", varname)
Hello lewis
在python2中: -
In [185]: varname = raw_input("what is your name?: ") #don't use `input()`
what is your name?: lewis
In [186]: print ("Hello", varname)
('Hello', 'lewis')