+ 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.

26th Feb 2017, 1:05 PM
Andrea Mattè
Andrea Mattè - avatar
1 Respuesta
- 1
2
12th Mar 2017, 4:06 AM
fsuper