assert condition assert condition, expr
__debug__
is True
, assert condition
checks if condition
is True
and raises an AssertionError
exception otherwise. expr
is also present, it passes expr
to the constructor of AssertionError
. lst = [] try: assert len(lst) print('-'.join(lst)) except AssertionError: print('assertion failed')