【发布时间】:2020-08-17 13:32:23
【问题描述】:
import sys
lst = ['b', 0, 2,5]
for entry in lst:
try:
print("****************************")
print("The entry is", entry)
r = 1 / int(entry)
except(ValueError):
print("This is a ValueError.")
except(ZeroDivisionError):
print("This is a ZeroError.")
except:
print("Some other error")
print("The reciprocal of", entry, "is", r)
当程序将输入作为 2 时,除了块之外的打印语句将被跳过。但如果我只在列表中给出 3 个元素,它就可以正常工作。
【问题讨论】:
标签: python try-except