Consider the following code:
try:
a = []
a[4] = 4
except ZeroDivisionError:
print('h')
finally:
print('y')
The output shows that the finally clause was executed:
y
Traceback (most recent call last):
File "work/finally.py", line 3, in <module>
a[4] = 4
IndexError: list assignment index out of range
However, if I change the try clause to something like this:
[] += [] - []
Then the finally clause doesn't get executed:
File "work/finally.py", line 2
[] += [] - []
^
SyntaxError: illegal expression for augmented assignment
What is the reason of this behavior? Where could I read about that? I didn't find it in the docs.