好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

异常处理与异常类型实例

异常处理

 1 #!usr/bin/env python 2 #-*-coding:utf-8-*- 3 # Author calmyan 4  5 list_l=['g','h'] 6 data={'一':'3'} 7 try: 8     #list_l[3]#IndexError: list index out of range 9     data['2q']10 except IndexError as e:#列表下标超出边界11     print(e)12 except KeyError as e:#字典key 不存在13     print('没有这个KEY',e)14 except Exception as e:##大部分异常都可捕获15     print(e)16 else:#结合使用17     print('以上正常')18 finally:19     print('最后都要打印') 

查看更多关于异常处理与异常类型实例的详细内容...

  阅读:43次