美文网首页
【Python】try catch 或者 try except

【Python】try catch 或者 try except

作者: 盐果儿 | 来源:发表于2024-08-19 15:45 被阅读0次

    try catch 是 Java 里的,try except 是 Python 里的。

    try... else... finally...

    try:

      result = 10 / 2

    except ZeroDivisionError:

      print("Cannot divide by zero.")

    else:

      print("Division successful!")

    finally:

      print("This block always executes.")

    捕获所有异常:

    try:

      ...

    except Exception as e:

      ...

    多个except异常:

    try:

      ...

    except ValueError as ve:

      ...

    except ZeroDivisionError as zde:

      ...

    相关文章

      网友评论

          本文标题:【Python】try catch 或者 try except

          本文链接:https://www.haomeiwen.com/subject/qgapkjtx.html