Built-in Exceptions

IndentationError — exception class

A syntax error caused by incorrect block indentation. Indentation defines suites in Python; align sibling statements and indent the body following a block header. TabError is a specialization. Catch IndentationError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
IndentationError

Return Value

type

The class object IndentationError; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
try:    compile("if True:\nprint(1)", "<demo>", "exec")except IndentationError as error:    print(type(error).__name__)
Python Reference