标签:异常处理 出错 val 处理 大写 不能 strong 信息 int
Except 后面可以捕捉任何异常,大写英文字母开头。。。
first = input(‘请输入除数:‘)
second = input(‘请输入被除数:‘)
try:
first = int(first)
second = int(second)
res = first/second
except ValueError as e: #这个e代表错误信息
print(e)
print(‘请输入整数‘)
except ZeroDivisionError as e:
print(‘除数不能为0‘)
except Exception as e: #上面代码出异常的时候走这里
print(e)
print(‘出错异常‘)
else: #没有出错
print(‘并没有出错‘)
finally:
print(‘最后结局‘)
标签:异常处理 出错 val 处理 大写 不能 strong 信息 int
原文地址:https://www.cnblogs.com/duanjialin007/p/9058468.html