在Python 2.7中,input()
将输入评估为代码,因此需要用引号引起来。 Python 2.7具有称为raw_input()
的方法,该方法将所有输入视为字符串(不需要引号)。
在Python 3.x中,将Python 2.7 raw_input()
方法重命名为input()
,并且将python 2.7 input()
功能替换为eval(input())
因此您可以在Python 2.7中使用raw_input()
或切换到Python 3.x
请确保您是在Python 3而不是Python 2上运行代码。在python 2上,您需要用“”
引用输入尽管似乎对此有多种解决方案: