常见的异常种类
常見的異常
NameError 找不到這個名字 要么變量 要么函數(shù)ValueError 在調用一個函數(shù)時給的的值不正確
TypeError 類型錯誤 例如字符串與數(shù)字加減乘除 調用一個不能被調用的類型
ZeroDivisionError 除數(shù)不能為0
KeyError 沒有這個key
IndexError 索引不存在
StopIteration 沒有更多的值可以迭代
FileNotFoundError 文件不存在
io.UnsupportedOperation 文件的操作不支持
AttributeError 沒有這個屬性
KeyboardInterrupt 程序被強行終止 ctrl+c ? AttributeError class Foo:pass f1 = Foo() f1.x
FileNotFoundError
with open("xxxx.py","rt") as f:#文件不存在f.read()ValueError
with open("異常.py","rt") as f:#文件不存在pass f.read() ZeroDivisionError 1/0KeyError
{}["a"]IndexError
l =[1,2,3] l[4]StopIteration
def shengchengqi():yield "a"yield "bb"s1 = shengchengqi() next(s1) next(s1) next(s1)#超出生成器的限界主要常見的異常就這些。
?
轉載于:https://www.cnblogs.com/msj513/p/9889549.html
總結
- 上一篇: Linux中添加和删除用户
- 下一篇: 010.KVM虚机冷迁移