SyntaxError
ZeroDivisionError
KeyError
(解释器)语法错误,比如缺了冒号,多了括号,少了引号等等
是唯一不是在运行时发生的异常
NameError
字面上的意思可以理解为在命名空间里找不到名字的错误。也就是:
python认为你使用了没有定义的变量
举个栗子:
>>> name = star
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'star' is not defined
>>>
ZeroDivisionError
除数为0啦
IndexError
请求的索引超出范围
举个栗子:
>>> food=['cake','apple','meat']
>>> food[5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> tools=[]
>>> tools[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>>
KeyError
你在字典里找一个并不存在的key,就是请求一个不存在的字典关键字
IOError
类似尝试打开一个不存在的磁盘文件
AttributeError
尝试访问未知的对象属性
IndentationError:
都知道Python是对格式要求很严格的,写了一些python但是也没发现他严格在哪里,今天遇到了IndentationError: unexpected indent错误我才知道他是多么的严格。
以后遇到了IndentationError: unexpected indent你就要知道python编译器是在告诉你“Hi,老兄,你的文件里格式不对了,可能是tab和空格没对齐的问题,你需要检查下tab和空格了”。
http://blog.163.com/kylandzwr_39/blog/static/180285039201138103914582/