python異常處理之return

spider_fu發表於2020-12-18

return 無法阻止程式進入finally

m = 2


def fun():
    try:
        n = m / 0
        return 1
    except Exception as err:
        print(err)
        return 2
    finally:
        return 3


if __name__ == "__main__":
    result = fun()
    print(result)

結果

division by zero
3

相關文章