我有一个字符串变量test
,在Python 2.x中这很正常。
test = raw_input("enter the test")
print test
但在 Python 3.x 中,我执行以下操作:
test = input("enter the test")
print test
使用输入字符串sdas
时,我收到了错误消息
Traceback (most recent call last):
File "/home/ananiev/PycharmProjects/PigLatin/main.py", line 5, in <module>
test = input("enter the test")
File "<string>", line 1, in <module>
NameError: name 'sdas' is not defined
print test
语句不是 Python 3.x 的语法:应该写成print(test)
。现在,Python 会把 test 当作一个命令来执行。 - jcoppens