IndentationError or TabError

  • Python

You may see

IndentationError: expected an indented block after function definition on line 1
IndentationError: unindent does not match any outer indentation level
IndentationError: unexpected indent
TabError: inconsistent use of tabs and spaces in indentation

Why it happens

  • A line has too many or too few spaces.
  • Tabs and spaces are mixed, often after copying.

How to fix it

  1. Use four spaces for each step.
  2. Select the lines and press Tab or Shift+Tab.
  3. In VS Code click Spaces: 4 at the bottom right and choose Convert Indentation to Spaces.

It worked if: It runs past that line.

Seen in a real run (some lines are close variants of it). Produced with Python 3.13 on Windows.

Didn't help? Search another error or ask us.