python7.1处理异常

a=[21,32,43,0,32,"a"]
for i in a:#取出元素

try:#写可能会报错的代码
print(3/i)

except Exception as e:#捕获try异常e
print("出现错误,错误是:",e)#出现异常的语句

else:
print("......正常......")#没有异常的语句

finally:
print("本次结束")#无论是否有异常,都执行!
#NameError:没有定义变量
#SytaxError:语法错误(少冒号、没有空格)
#IOError:文件不存在
#ZeroDivsionError:除数是0
#IndentationError:缩进问题

 

posted @ 2019-07-01 10:51  千钧蚁  阅读(185)  评论(0)    收藏  举报