Built-in Exceptions
AssertionError — exception class
Signals an unsuccessful assertion in non-optimized code. Assertions document internal invariants; -O can remove them entirely, so use explicit validation for user input and security requirements. Catch AssertionError when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
AssertionErrorReturn Value
type
The class object AssertionError; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
try: assert 2 == 3, "invariant"except AssertionError as error: print(type(error).__name__)