在Python中的用户输入后,“NameError:name‘未定义”我完全不明白为什么这不管用。应该准确地工作,对吧?UserName = input("Please enter your name: ")
print ("Hello Mr. " + UserName)
raw_input("<Press Enter to quit.>")我明白这个例外:Traceback (most recent call last):
File "Test1.py", line 1, in <module>
UserName = input("Please enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'k' is not defined上面写着NameError 'k',因为我写了'k'作为我测试中的输入。我读过打印语句曾经没有括号,但这已经被废弃了,对吗?
3 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
input()
help(input)
k
, input()
k
NameError
raw_input()
input()
如果input()
k
>>> UserName = input("Please enter your name: ") Please enter your name: "k" >>> print UserName k
Qyouu
TA贡献1786条经验 获得超11个赞
NameError
input()
username = input('...') # => translates to username = eval(raw_input('...'))
bob
username = eval('bob')
eval()
username = bob => NameError print ("Hello Mr. " + username)
username = "bob" print ("Hello Mr. " + username) => Hello Mr. bob
添加回答
举报
0/150
提交
取消