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('最后都要打印')
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did84935