在最新版本中使用Python输入函数时出错
我使用最新版本的Python 3.6.1 我在脚本中使用在最新版本中使用Python输入函数时出错,python,python-3.x,input,Python,Python 3.x,Input,我使用最新版本的Python 3.6.1 我在脚本中使用input()函数 F:\MyPython> type new.py input_variable = input("Enter your name: ") print ("your name is" + input_variable) 我得到以下错误: Traceback (most recent call last): File "F:\MyPython\new.py", line 1, in <module>
input()
函数
F:\MyPython> type new.py
input_variable = input("Enter your name: ")
print ("your name is" + input_variable)
我得到以下错误:
Traceback (most recent call last):
File "F:\MyPython\new.py", line 1, in <module>
input_variable = input("Enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'xyz' is not defined
回溯(最近一次呼叫最后一次):
文件“F:\MyPython\new.py”,第1行,在
输入变量=输入(“输入您的姓名:”)
文件“”,第1行,在
名称错误:未定义名称“xyz”
但是当我使用raw\u input()
时,我得到了正确的输出
为什么即使在安装了最新版本后,input()
仍会出现错误?这不是错误
x=input(“”)
只接受整数作为输入
x=raw\u输入(“”)表示字符串
您可能正在尝试使用input()方法输入“string”。您正在调用xyz,而没有对其进行定义或赋值。你能展示你所写的代码吗?你确定你在使用Python 3.6.1吗?是的,它是3.6.1,请发布你的代码。输入变量=输入(“输入你的名字:”)打印(“你的名字是”+输入变量)不正确`x=input(“”)至少在Python3.6.1IMO中接受字符串作为输入,这在Python2中是正确的,但在Python3中不是。