python - 无法运行Python脚本

这是我的代码:

name = input("What's your name? ")
print("Nice to meet you " + name + "!")

但是当我输入一个名称(例如“john”)时,它给了我这个错误:
Traceback (most recent call last):
  File "name.py", line 1, in <module>
    name = input("What's your name? ")
  File "<string>", line 1, in <module>
NameError: name 'john' is not defined

我正在使用的python版本是“2.7.10”。

最佳答案

您需要使用raw_input而不是input,因为后者尝试评估您输入的内容,而前者则将其保留为字符串。

https://stackoverflow.com/questions/31172607/

相关文章:

macos - 指定编译器 Homebrew 安装

generics - TypeScript 泛型类 : Cannot assign to Gener

c# - 为什么调用此列表方法会返回不可访问错误?

c# - 引用Shell32.dll?

compiler-errors - 药剂: Why do I get “undefined func

c# - 错误: [feature] requires a Business (or higher)

c++ - Visual Studio中D8049错误的原因是什么?

python - 在 Python 中不使用\n 的新行

java - 无法访问 org.eclipse.core.runtime.IProgressMoni

r - 使用 R 包 brms 时出错