python错误捕获练习

一:错误捕获联系例子

#codeing=utf-8
def test_index(string,index):
    print string[index];

str="thiistest";
num=3;
try:#尝试运行
    test_index(str,num);
except IndexError:#except后面跟随错误类型
    print "索引类型错误";    
except TypeError as s: #python语法错误赋值给s在错判断
    
else:
    print "没有错误发生";    
finally:
    print "不管有没有错误都会走";
原文地址:https://www.cnblogs.com/zh718594493/p/12384515.html