当我使用异常处理在Python中编写代码时,我可以编写如下代码:
try:
some_code_that_can_cause_an_exception()
except:
some_code_to_handle_exceptions()
else:
code_that_needs_to_run_when_there_are_no_exceptions()
Run Code Online (Sandbox Code Playgroud)
这有什么不同于:
try:
some_code_that_can_cause_an_exception()
except:
some_code_to_handle_exceptions()
code_that_needs_to_run_when_there_are_no_exceptions()
Run Code Online (Sandbox Code Playgroud)
在这两种情况下code_that_needs_to_run_when_there_are_no_exceptions()都会在没有例外时执行.有什么不同?