PlainError

IndentationError: unexpected indent

Last checked 2026-10-26 · 2 fixes · reviewed answer

TL;DRThis Python error happens when a line of code starts with the wrong amount of spaces or tabs compared to the surrounding code, breaking the required structure.

Most likely cause: Mixing tabs and spaces for indentation in the same file or block

Try first: Open the file in a text editor and check the reported line

Likely causes

  1. Mixing tabs and spaces for indentation in the same file or blockmost likely
  2. An extra or misplaced indent on a line that should align with otherspossible
  3. Copy-pasting code that brought inconsistent spacing from another sourceless likely

How to fix it

Safest first: SafeChanges settingsDangerous
  1. Open the file in a text editor and check the reported lineSafe

    Look at the exact line number shown in the full error message and count the leading spaces or tabs to ensure they match the block above it.

  2. Convert all indentation to spaces onlyChanges settings

    Select the entire code and replace any tab characters with the equivalent number of spaces (usually 4 per level).

If that didn't fix it

Paste the full error message including the line number and a few lines of surrounding code into an online Python syntax checker.

When to see a technician

If the code is part of a larger application or you cannot locate the mismatched indent after checking the file, ask an experienced Python developer to review it.

Quick answers

What does IndentationError: unexpected indent mean?
This Python error happens when a line of code starts with the wrong amount of spaces or tabs compared to the surrounding code, breaking the required structure.
What causes IndentationError: unexpected indent?
Mixing tabs and spaces for indentation in the same file or block. (most likely) An extra or misplaced indent on a line that should align with others. (possible) Copy-pasting code that brought inconsistent spacing from another source. (less likely)
How do I fix IndentationError: unexpected indent?
Try these in order, safest first: 1. Open the file in a text editor and check the reported line. 2. Convert all indentation to spaces only.
What if that didn't fix it?
Paste the full error message including the line number and a few lines of surrounding code into an online Python syntax checker.
When should I see a technician?
If the code is part of a larger application or you cannot locate the mismatched indent after checking the file, ask an experienced Python developer to review it.
Did this fix it? Report a problem

Related errors

All Coding errors →