首页 > 解决方案 > 为什么 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

解决方案


确保您使用 Python 3 作为解释器。据我所知,Python 2 有一些其他的输入语法。


推荐阅读