How to use the Python Indentation Error Fixer
- 1. Paste your codePaste the Python that gives IndentationError or TabError.
- 2. FixChoose 4 or 2 spaces and press Fix indentation.
- 3. Check and copyRead the list of fixes, then copy or download the cleaned code.
Worked example
The sample has 5 problems: line 2 uses a tab and line 3 mixes a tab with spaces; line 5 (return "A+") isn't indented under elif; line 10 (print) isn't indented under the for loop; and line 11 has an unexpected extra indent. The fixed code compiles, and running it prints 95 O, done, 82 A+, done, 60 B, done, because the fixer keeps line 11 inside the loop, where its indentation suggested it belonged. If you meant print("done") to run once after the loop, move it out by hand.
What each error means
- Expected an indented block: a line ending in a colon (if, for, def, class) must be followed by an indented line.
- Unexpected indent: a line is indented more than the block it's in, without a colon above.
- Unindent does not match: a line moves back out to a level that no outer block uses.
- TabError: tabs and spaces are mixed in a way Python can't interpret consistently.
Limits
Indentation is part of Python's grammar, so sometimes the fixer has to guess which block a line belongs to; it chooses based on the indentation you had. It leaves lines inside multi-line brackets, triple-quoted strings and backslash continuations unchanged, and it doesn't fix other syntax errors. Every fix is listed with its line number, so check those lines before running the code. In editors, set tabs to insert 4 spaces to avoid these errors.
Frequently asked questions
Does it change my code's logic?
Only where indentation is ambiguous, which is listed. Review those lines.
Is my code uploaded?
No. It's fixed in your browser.
Which indent size should I use?
4 spaces, as PEP 8 recommends. Choose 2 if your project uses it.
Is the Python indentation fixer free?
Yes. You can use the Python indentation fixer without signing up. The first time you run it, we ask once for your name and WhatsApp number; after that the Python indentation fixer and every other Uncodemy tool open straight away.