“NameError: name '' 未定义";用户在 Python 中输入后 [英] "NameError: name '' is not defined" after user input in Python

查看:51
本文介绍了“NameError: name '' 未定义";用户在 Python 中输入后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全不知道为什么这不起作用.应该准确地工作,对吗?

I'm completely lost as to why this isn't working. Should work precisely, right?

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' 作为输入.我读过打印语句以前没有括号,但现在已被弃用,对吗?

It says NameError 'k', because I wrote 'k' as the input during my tests. I've read that the print statement used to be without parenthesis but that has been deprecated right?

推荐答案

不要在 2.x 中使用 input().使用 raw_input() 代替.总是.

Do not use input() in 2.x. Use raw_input() instead. Always.

这篇关于“NameError: name '' 未定义";用户在 Python 中输入后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆