Python错误及异常
1缩进错误
IndentationError: unexpected indent
ttt1=1
ttt2=2
2 语法错误
SyntaxError: invalid syntax
printf 'ffff'
SyntaxError: keyword can't be an expression
test='i am {name}, i am {age} old' print test v=test.format('name'='pzq',age='19) # 此处 'name' 不应加引号 print v
3 变量未定义 (未声明/初始化对象 没有属性)
NameError: name 'test1' is not defined
Abcd='ffff' print abcd
4 对类型无效的操作
TypeError: 'str' object is not callable
func='abcde' func()
5 参数错误
ValueError: substring not found
x='abcde' print x.index('f')
6 序列索引错误( 数据越界比较常见)
IndexError: string index out of range
x='abcde' print x[5]
7 对象属性错误
AttributeError: 'str' object has no attribute 'substring'
xxx='abcde' xxx.substring('f')
8 导入错误
ImportError: No module named chardet
import chardet