致力于为学生创建语法调试练习。我们有以下例子。
def five():
print('five')
return 5
def hello();
print('hello')
Run Code Online (Sandbox Code Playgroud)
但是在运行文件时,语法错误是
def hello();
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我已经看遍了,但无法弄清楚为什么编译器 [原文如此] 不抱怨函数外部的 return 关键字,而是首先找到它下面的分号错误。
Python以什么顺序检查文件语法?这是规范的一部分还是实现定义?