- assert
- raise
- Exception
assert to verify values
examples/modules/raise_exception.py
def add(x, y): return x * y for x, y, z in [(2, 2, 4), (9, 2, 11), (2, 3, 5)]: print(f"add({x}, {y}) == {z}") if add(x, y) != z: raise Exception(f"add({x}, {y}) != {z}") #raise AssertionError
add(2, 2) == 4 add(9, 2) == 11 Traceback (most recent call last): File "examples/functions/raise_exception.py", line 7, in <module> raise Exception(f"add({x}, {y}) != {z}") Exception: add(9, 2) != 11
examples/modules/assert.py
def add(x, y): return x * y for x, y, z in [(2, 2, 4), (9, 2, 11), (2, 3, 5)]: print(f"add({x}, {y}) == {z}") assert add(x, y) == z
add(2, 2) == 4 add(9, 2) == 11 Traceback (most recent call last): File "examples/functions/assert.py", line 6, in <module> assert add(x, y) == z AssertionError