try_except_finally

来源:互联网 发布:网络阅卷软件 编辑:程序博客网 时间:2024/05/12 23:06
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
0 0