Search notes:

assert

Python: assert statement
assert condition
assert condition, expr
assert …. does nothing if __debug__ is False.
If __debug__ is True, assert condition checks if condition is True and raises an AssertionError exception otherwise.
If the optional expression 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')
Github repository about-Python, path: /statements/assert/demo.py

See also

statements

Index