Wann ist es notwendig, eine `else` -Klausel zu einem try..except in Python hinzuzufügen?
Wenn ich Code in Python mit Ausnahmebehandlung schreibe, kann ich Code wie folgt schreiben:
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()
Wie unterscheidet sich das von:
try:
some_code_that_can_cause_an_exception()
except:
some_code_to_handle_exceptions()
code_that_needs_to_run_when_there_are_no_exceptions()
In beiden Fällencode_that_needs_to_run_when_there_are_no_exceptions()
wird ausgeführt, wenn keine Ausnahmen vorliegen. Was ist der Unterschied?