assert statements

https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement

ASSERTIONS

Assert statements are a convenient way to insert debugging assertions into a program.


# Syntax.
# The name __debug__ is true if Python was not started with an -O option.
# Try 'python3 --help' in the shell to see other options.

assert expression

# It is equivalent to
# if __debug__:
#     if not expression: raise AssertionError

assert expression1, expression2

# It is equivalent to
# if __debug__:
#     if not expression1: raise AssertionError(expression2)

assert False              # AssertionError
assert False, 'message'   # AssertionError: message
assert False, 2 + 2       # AssertionError: 4