Python中常见的异常 1、除数为零异常(ZeroDivisionError) # coding:utf-8print(10/0) 2、索引无效异常(IndexError) # coding:utf-8lis = [1, 2, 3, 4]print(lis[4]) 3、数据类型不匹配异常(TypeError) # coding:utf-8print(1 '
Python中常见的异常
1、除数为零异常(ZeroDivisionError)
# coding:utf-8
print(10/0)
2、索引无效异常(IndexError)
# coding:utf-8
lis = [1, 2, 3, 4]
print(lis[4])
3、数据类型不匹配异常(TypeError)
# coding:utf-8
print(1 > 'hj')
4、键值无效异常(KeyError)
# coding:utf-8
dic = {"code":1001, "name":"zhang"}
print(dic["key"])
5、语法异常(SyntaxError)
# coding:utf-8
int a = 1
6、参数值异常(ValueError)
# coding:utf-8
a = int('hj')