在python
中如果可以的话,我们可以使用在引发关键字之后初始化变量。例如
Try:
func(x)
except ValueError
raise
data = {}
或
Try:
func(x)
except Exception
data = {}
答案 0 :(得分:0)
它使用引发的参数退出程序:
尝试的代码:
try:
print(3+2)
finally:
print('Goodby World!')
raise KeyboardInterrupt
print(343)
输出:
5
Goodby World!
Traceback (most recent call last):
File "lists.py", line 5, in <module>
raise KeyboardInterrupt
KeyboardInterrupt