python - 为什么 Pycharm 中的输入函数在输入字符串时不起作用?
问题描述
name = input('what is your name? ')
print('hi ' + name)
输出显示:
what is your name? John
Traceback (most recent call last):
File "/Users/xx/PycharmProjects/Tutorial/basic_tutorial.py", line 1, in <module>
name = input('what is your name? ')
File "<string>", line 1, in <module>
NameError: name 'John' is not defined
输入不带引号的 John 时它不起作用。但是,我相信 Pycharm 中的语法没有错。有谁知道为什么?
解决方案
确保您使用 Python 3 作为解释器。据我所知,Python 2 有一些其他的输入语法。
推荐阅读
- java - 将 LocalizationBundle 文件添加到可运行的 Jar、Java、Eclipse
- sql - 我想创建一个搜索功能,它会显示一张专辑中的歌曲列表
- tensorflow2.0 - 获取“ValueError:找不到匹配的函数来调用从 SavedModel 加载的函数。” 关于训练模型
- plotly-dash - dash_table 不代表真正的数据框
- python - Discord.py 如何在 message.content 中获取附件
- javascript - 使 bootstrap 下拉菜单中的 span 可点击并防止隐藏
- firebase - 在 github 操作中部署到 PR 上的 Firebase 托管失败
- python - 将上传的带有换行符的 .txt 文件存储在变量 Django 中
- c++ - MPI_Gather 我做错了什么?
- apache-spark - 气流 SparkSubmitOperator 失败,因为:初始作业未接受任何资源;错误