"""
NameError
"""# 函数名拼写错误# prlnt('hello world')# NameError: name 'prlnt' is not defined. Did you mean: 'print'?# 变量名拼写错误
a ='111'# print(aa) #NameError: name 'aa' is not defined. Did you mean: 'a'?# 使用一个不存在的变量# print(b) # NameError: name 'b' is not defined'''
SyntaxError
'''# if 'he' == 'hi'# print('hello')#SyntaxError: expected ':''''
IndentationError
'''# if 'he' == 'hi':# print('hello') # IndentationError: expected an indented block after 'if' statement on line 11'''
TypeError
'''# print(3+'2')#TypeError: unsupported operand type(s) for +: 'int' and 'str'
tp =(1,3,5)# tp[2]=4# print(tp) #TypeError: 'tuple' object does not support item assignment'''
AttributeError
'''# tp.append(2)# print(tp)#AttributeError: 'tuple' object has no attribute 'append''''
KeyError
'''
d ={1:2,3:4}# print(d[2])#KeyError: 2'''
IndexError
'''print(tp[4])#IndexError: tuple index out of range
try:
n =int(input('请输入数字:'))
n =5/ n
print(n)except ZeroDivisionError as e:print('除数不能为0')print('原始报错信息', e)except:print('请输入一个数字')else:print('运行没有被except语句捕获,执行else模块')finally:print('无论如何都要执行finally模块')
raise关键字
try:
pwd =input('请输入密码:')iflen(pwd)<8:raise Exception("密码长度不够")except Exception as e:print(e)
')iflen(pwd)<8:raise Exception("密码长度不够")except Exception as e:print(e)