三白草

注册

 

发新话题 回复该主题

ErrorsandException [复制链接]

1#

无意中发现几篇很nice的Python英文推文,思路、结构都清晰。在此,结合自己的coding心得,对内容重新梳理、加以充实,虽然都是英文的,但是木有想象中的难的,加油看哈!

本节知识点:Python中的ErrorsandExceptions

QQ图片31

基本概念

Syntaxerrors

logicalerrors(Exception)

Exception汇总

BaseClasses

exceptionBaseException

exceptionException

exceptionArithmeticError

exceptionBufferError

exceptionLookupError

Concreteexceptions

1、exceptionAssertionError

2、exceptionAttributeError

3、exceptionEOFError

4、exceptionFloatingPointError

5、exceptionGeneratorExit

6、exceptionImportError

7、exceptionModuleNotFoundError

8、exceptionIndexError

9、exceptionKeyError

10、exceptionKeyboardInterrupt

11、exceptionMemoryError

12、exceptionNameError

13、exceptionNotImplementedError

14、exceptionOSError([arg])

15、exceptionOverflowError

16、exceptionRecursionError

17、exceptionReferenceError

18、exceptionRuntimeError

19、exceptionStopIteration

20、exceptionSyntaxError

21、exceptionSystemError

22、exceptionSystemExit

23、exceptionTypeError

24、exceptionUnboundLocalError

25、exceptionUnicodeError

26、exceptionValueError

27、exceptionZeroDivisionError

References

Motto

基本概念

在Python中,倘若我们的代码无法顺溜的执行下去,通常是因为以下两种情况:

Syntaxerrors

Logicalerrors(Exceptions)

前者为语法错误,如果不按规定的语法格式撸代码,那么Python解释器就看不懂你写的文字,自然而言就会报错,这个很好理解;后者表示逻辑错误,如果你的代码出现了1/0、或者dict中你检索的key不存在,代码自然无法顺溜的执行下去,只能被迫中断。

从报错的时间节点上仔细体会一下,以上两种分类还是有所区别的:语法错误通常在代码执行前,这一句代码如果不符合语法规则,那么代码就会报错;异常(Exception)通常出现在代码执行过程中,比如一个包含除法的function,在第1次、第2次调用的时候都表现正常,但是在第3次调用的时候报错了,那你也得终止这个过程

Syntaxerrors

#initializetheamountvariableamount=#checkthatYouareeligibleto#purchaseDsaSelfPacedornotif(amount)print("YouareeligibletopurchaseDsaSelfPaced")

输出结果:

File"D:/

分享 转发
TOP
发新话题 回复该主题