小编Nic*_*ley的帖子

Python 以什么顺序查找语法错误?

致力于为学生创建语法调试练习。我们有以下例子。

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以什么顺序检查文件语法?这是规范的一部分还是实现定义?

python syntax parsing syntax-error python-3.x

14
推荐指数
1
解决办法
268
查看次数

标签 统计

parsing ×1

python ×1

python-3.x ×1

syntax ×1

syntax-error ×1