First page Back Continue Last page Overview Graphics

The assert Statement

The assert statement is intended for debugging statements.

It can be seen as an abbreviated notation for a conditional raise statement:

if not <some_test>:

raise AssertionError(<message>)

This can be written as:

assert <some_test>, <message>

In other words:

If <some_test> evaluates to False, an exception is raised and <message> will be output.