IndentationError

Built-in ExceptionPython 2.0+Beginner

Raised when indentation is incorrect

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching IndentationError
try:
    exec("  x = 1")
except IndentationError as e:
    print(f"Caught IndentationError: {e}")
    print(f"Type: {type(e).__name__}")

IndentationError is raised when raised when indentation is incorrect. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore