鱼C论坛

 找回密码
 立即注册
查看: 2241|回复: 0

[技术交流] 零基础入门学习python第三十二讲

[复制链接]
发表于 2017-9-3 15:49:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 足迹 于 2017-9-3 15:50 编辑

错误exception

详细见
Python 标准异常总结
http://bbs.fishc.com/thread-45814-1-1.html
(出处: 鱼C论坛)

主要错误
AssertionError
  1. >>> a=['123']
  2. >>> assert len(a)>0
  3. >>> a.pop()
  4. '123'
  5. >>> assert len(a)>0
  6. Traceback (most recent call last):
  7.   File "<pyshell#3>", line 1, in <module>
  8.     assert len(a)>0
  9. AssertionError
复制代码


AtributeError
  1. >>> a=[123]
  2. >>> a.ser()
  3. Traceback (most recent call last):
  4.   File "<pyshell#5>", line 1, in <module>
  5.     a.ser()
  6. AttributeError: 'list' object has no attribute 'ser'
复制代码


typeError
  1. >>> 1+'1'
  2. Traceback (most recent call last):
  3.   File "<pyshell#6>", line 1, in <module>
  4.     1+'1'
  5. TypeError: unsupported operand type(s) for +: 'int' and 'str'
复制代码


zeroDivitionError
  1. >>> 2/0
  2. Traceback (most recent call last):
  3.   File "<pyshell#7>", line 1, in <module>
  4.     2/0
  5. ZeroDivisionError: division by zero
  6. >>>
复制代码


IndexError
  1. >>> a=[1,2,3]
  2. >>> a[3]
  3. Traceback (most recent call last):
  4.   File "<pyshell#10>", line 1, in <module>
  5.     a[3]
  6. IndexError: list index out of range
复制代码


NameError
  1. >>> b
  2. Traceback (most recent call last):
  3.   File "<pyshell#11>", line 1, in <module>
  4.     b
  5. NameError: name 'b' is not defined
复制代码


KeyError
  1. >>> dict1={'one':1,'two':2,'three':3}]
  2. >>> dict1['one']
  3. 1
  4. >>> dict1['four']
  5. Traceback (most recent call last):
  6.   File "<pyshell#19>", line 1, in <module>
  7.     dict1['four']
  8. KeyError: 'four'
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-5 00:42

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表