• 技术文章 >Python技术 >Python基础教程

    python异常模块的整理

    小妮浅浅小妮浅浅2021-02-25 16:11:09原创2586

    1、OSError异常

    OSError是操作系统相关异常。

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

    2、IndexError异常

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

    IndexError: list index out of range

    3、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快捷代码片段的使用,希望能对大家有所帮助。更多Python学习指路:python基础教程

    专题推荐:python异常
    品易云
    上一篇:Python快捷代码片段的使用 下一篇:python如何使用import()实现插件

    相关文章推荐

    • python字符串的拆分与合并• pickle模块在Python的函数使用• python中如何统计列表中元素出现的频率?• Python中pickle模块的使用注意• python中条件判断分为哪几类?• python中conftest如何使用?• python常见循环结构有哪些• Python快捷代码片段的使用

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网