IndexError
IndexError: tuple index out of range
tuple类型索引出界了
print((1,2)[3])
IndexError: pop from empty list
从空的list中删除
print([].pop(1))
ImportError
ImportError: No module named 'sy'
没有模块名字叫sy
import sy
KeyError
KeyError: 4
没有4这个键
print({1:11, 2:22, 3:33}[4])
KeyError: 'popitem(): dictionary is empty'
字典是空的
{}.popitem()
NameError
NameError: name 'k' is not defined
变量k没有定义
print(k)
SyntaxError
SyntaxError: invalid syntax
不合规范的语法
for i in range(0,10)):
TypeError
TypeError: 'int' object is not subscript able
创建包含一个元素的元组,要在该元素后面添加一个逗号。
print((1,)[0])
print((1)[0])
TypeError: 'tuple' object does not support item assignment
该类型不支持此操作(改值)
(1,2)[0]=0
TypeError: not all arguments converted during string formatting
参数多了
print("%d" % (1,2))
TypeError: not enough arguments for format string
参数少了
print("%d %d" % 1)
TypeError: pop expected at least 1 arguments, got 0
参数少了(至少一个,一个也没有得到)
print(dt.pop())
TypeError: insert() takes exactly 2 arguments (1 given)
要两个参数只给了一个
print([].insert(6))
TypeError: unhashable type: 'list'
list类型是不能做为键(不可哈希)的类型
print({[1,]:11, 2:22}[[1,]])
TypeError: 'myTest' is an invalid keyword argument for this functionmyTest不是print方法的默认参数,不能这样写
print(myTest=3)
UnboundLocalError
UnboundLocalError: local variable 'i' referenced before assignment
引用局部变量i前应该定义
i*=2
ValueError
ValueError: range() arg 3 must not be zero
range方法的第三个参数不可为0for i in range(1, 3, 0):
ZeroDivisionError
ZeroDivisionError: division by zero
除数不能为0print(5/0)