python异常模块的整理

267次阅读
没有评论

python异常模块的整理

python OSError异常

OSError是操作系统相关异常。

FileNotFoundError:[Error 2] No such file or directory: 'abc.txt'

python IndexError异常

IndexError异常是访问序列元素时,下标索引超出取值范围所引发的异常。

IndexError: list index out of range

python ValueError异常

ValueError异常是由于传入一个无效的参数值而引发的异常。

>>> i = 'QWE
>>> print(5 / int(i))
Traceback(most recent call last):
    File"<pyshell#22>", line1, in <module>
        print(5 / int(i))
ValueError: invalid literal for int() with base 10: 'QWE'

以上就是Python快捷代码片段的使用,希望能对大家有所帮助。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-05-04发表,共计458字。
新手QQ群:570568346,欢迎进群讨论 Python51学习