Python错误及异常

1缩进错误

IndentationError: unexpected indent

ttt1=1
 ttt2=2

2 语法错误

SyntaxError: invalid syntax

printf 'ffff'

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')

猜你喜欢

转载自www.cnblogs.com/ryanpan/p/9262751.html