考虑以下代码:
try:
a = []
a[4] = 4
except ZeroDivisionError:
print('h')
finally:
print('y')
输出显示finally子句已执行:
y
Traceback (most recent call last):
File "work/finally.py", line 3, in <module>
a[4] = 4
IndexError: list assignment index out of range
但是,如果我将try子句更改为这样的话:
[] += [] - []
然后finally子句不执行:
File "work/finally.py", line 2
[] += [] - []
^
SyntaxError: illegal expression for augmented assignment
此行为的原因是什么?我在哪里可以读到?我没有在文档中找到它。