Next / Previous / Contents / TCC Help System / NM Tech homepage

13.2. The assert statement

To check for “shouldn't happen” errors, you can use an assert statement:

assert e1
assert e1, e2

where e1 is some condition that should be true. If the condition fails, an AssertionError exception is raised (see exceptions below). If a second expression e2 is provided, the value of that expression is passed with the exception.

Assertion checking can be disabled by running Python with the -O (optimize) option.