Python 中如何处理异常?
Python 使用 try...except...else...finally 语法来处理异常:
try...except...else...finally
try
except
else
finally
示例:
try: x = 1 / 0 except ZeroDivisionError: print("除以零错误") else: print("没有错误") finally: print("这是总会执行的部分")