def myTry():
return(1/0)
i = [0,1,2,3]
try:
#myTry() #对应ZeroDivisionError
print(i[len(i)]) #对应Exception 即 LIST INDEX OUT OF RANGE
#pass #try里没有任何元素时 用pass直接跳过
except ZeroDivisionError as E:
print('ERROR:',str(E).upper())
except Exception as E:
print('ERROR:',str(E).upper())
finally:
print('I like Danielle') #不管上述代码如何 都输出 I like Danielle
try_except_finally
最新推荐文章于 2020-02-21 23:57:51 发布