开发过程中难免出现错误,而错误分成两种
1、语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正)
2、逻辑错误(逻辑错误)
异常就是程序运行时发生错误的信号,在python中,错误触发的异常如下:
在python中不同的异常可以用不同的类型(python中统一了类与类型,类型即类)去标识,不同的类对象标识不同的异常,一个异常标识一种错误
触发IndexError
l=[‘egon‘,‘aa‘] l[3]
触发KeyError
dic={‘name‘:‘egon‘} dic[‘age‘]
触发ValueError
s=‘hello‘ int(s)
ArithmeticError
AssertionError
AttributeError
BaseException
BufferError
BytesWarning
DeprecationWarning
EnvironmentError
EOFError
Exception
FloatingPointError
FutureWarning
GeneratorExit
ImportError
ImportWarning
IndentationError
IndexError
IOError
KeyboardInterrupt
KeyError
LookupError
MemoryError
NameError
NotImplementedError
OSError
OverflowError
PendingDeprecationWarning
ReferenceError
RuntimeError
RuntimeWarning
StandardError
StopIteration
SyntaxError
SyntaxWarning
SystemError
SystemExit
TabError
TypeError
UnboundLocalError
UnicodeDecodeError
UnicodeEncodeError
UnicodeError
UnicodeTranslateError
UnicodeWarning
UserWarning
ValueError
Warning
ZeroDivisionError
原文:https://www.cnblogs.com/jayxuan/p/10773203.html