70 - 描述异常捕捉语句中else 的作用

请通过代码说明try…except…else 中else 子句的作用

while True:
    try:
        x = int(input('请输入x:'))
        y = int(input('请输入y:'))
        value = x / y
        print('x / y is', value)
        
    except Exception as e:  # 发生异常时执行
        print('输入错误: ', e)
        print('请重新输入')
    else:  # 未发生异常时执行
        break
请输入x:a
输入错误:  invalid literal for int() with base 10: 'a'
请重新输入
请输入x:20
请输入y:0
输入错误:  division by zero
请重新输入
请输入x:1
请输入y:5
x / y is 0.2


71 - 使用Beautiful Soup 的节点选择器获取节点信息

发布了208 篇原创文章 · 获赞 249 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_29339467/article/details/104885957
70