• tabs
  • indentation

Indentation errors are a common beginner issue when first learning to program in Python.

How to fix each error depends on the specifics of the case. The canonical indentation errors post covers them all.

The specific errors covered:

  • IndentationError: unexpected indent
  • IndentationError: expected an indented block
  • TabError: inconsistent use of tabs and spaces in indentation
  • SyntaxError for continuation of a compound statement that was broken up by lack of indentation (e.g. else: no longer connected to if or for or while, etc.).

The post includes an intro, treatise on tabs vs spaces, and addresses each of the possible errors in turn.

Fixes include adding a body to compound statements (including pass), matching indentation levels, checking for mixed use of tabs and spaces.