爲什麼我們需要 Python 中的“finally”子句? - Why do we need the “finally” clause in Python?

問題:

I am not sure why we need finally in try...except...finally statements.我不確定爲什麼我們需要finally in try...except...finally語句。 In my opinion, this code block在我看來,這個代碼塊

try:
    run_code1()
except TypeError:
    run_code2()
other_code()

is the same with this one using finally :與使用finally這個相同:

try:
    run_code1()
except TypeError:
    run_code2()
finally:
    other_code()

Am I missing something?我錯過了什麼嗎?


解決方案:

參考一: https://stackoom.com/question/mTCW
參考二: Why do we need the “finally” clause in Python?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章