+ 2
Assertion with try and except: example
Code: print(1) assert 2 + 2 == 4 print(2) try: assert 1 + 1 == 3 except: #raise print("AssertionError") print(3) Output: 1 2 AssertionError 3 Without try and except, the assertion stops the program-> 3 is not printed.
1 Respuesta
- 1
2