0
In a try-except if u have more than 1 except, which 1 is going to be executed? The first exception it will catch or all of them?
try: print(1) assert 2+2==5 except AssertionError: print(3) except: print(4) # Is not (except:) stronger than (except EXCEPTION:)
4 Respostas
+ 6
If there's an exception, and it matches the exception classes of several "except" clauses, only the first one will be executed. In the example, you'll get "1" and "3" as the output.
EDIT: regarding the comment "is not (except:) stronger..." -> in fact, it means the default case, when there's an exception not caught by any former "except..." clause. So "except AssertionError" is executed and afterwards the control passes to the sentence below the whole "try" block (if exists).
+ 4
3
+ 1
Thanks a lot. I get it now :)
0
3 is the answer