CMD指令执行python程序时提示syntaxerror:onvalid syntax

2025-04-08 12:55:23
推荐回答(1个)
回答1:

随便用一个文本编辑器,打开你保存的文件,你就知道发生了什么。
IDLE默认打开的是交互模式,也就是你说的回车可以执行。你在这个模式下保存的是整个交互的信息,不只是代码。
你的py文件打开应该是这样的内容
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> print('hello world')
a
>>>
而不是
print('hello world')