SyntaxError: Unexpected Indent

IndentationError: unexpected indent

Quick Answer

Your code has incorrect indentation. Python uses indentation for code blocks. Use consistent 4-space indentation and do not mix tabs and spaces.

Why This Happens

Python uses indentation instead of braces. Every line in a block must have the same indentation. Mixing tabs and spaces or adding extra indentation causes this error.

The Problem

def greet(name):
    print(f'Hello, {name}')
        print('Welcome')

The Fix

def greet(name):
    print(f'Hello, {name}')
    print('Welcome')

Step-by-Step Fix

  1. 1

    Check indentation consistency

    All lines in the same block must have identical indentation.

  2. 2

    Convert tabs to spaces

    Configure your editor to use 4 spaces. Run python -tt to find mixed tabs/spaces.

  3. 3

    Check the previous line

    The line before may need a colon.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free