Python考试题--第74道题目--分析try-except-else中else子句的意义--2022年04月29日
原创目录
一、else的作用:
try-except-else中except子句中的代码在在发生异常时执行,并且else子句中的代码将在。try-except代码执行后,当代码正确执行时才会执行。
2.示例代码演示:
while True:
try:
x = int(input(请输入x:))
y = int(input(请输入y:))
value = x / y
print(value)
except Exception as e: # 在发生异常时执行
print(e)
print("输入错误,请重新输入。")
else: # 未发生异常执行
break
执行结果如下:

版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123




