assert expression, info
For instance,
>>> assert False, "Oopsie"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError: Oopsie
From the docs:
Assert statements are a convenient way
to insert debugging assertions into a
program:assert_stmt ::= "assert" expression ["," expression]The simple form,
assert expression, is equivalent toif __debug__: if not expression: raise AssertionErrorThe extended form
assert expression1, expression2is equivalent to
if __debug__: if not expression1: raise AssertionError(expression2)These equivalences assume that
__debug__andAssertionErrorrefer to the built-in variables with those
names. In the current implementation,
the built-in variable__debug__is
True under normal circumstances, False
when optimization is requested
(command line option -O). The current
code generator emits no code for an
assert statement when optimization is
requested at compile time. Note that
it is unnecessary to include the
source code for the expression that
failed in the error message; it will
be displayed as part of the stack
trace.