Python
IndentationError: unexpected indent
IndentationError
Python uses indentation for block structure. Mixed tabs/spaces or incorrect alignment causes this error.
Common Causes
- Mixing tabs and spaces
- Inconsistent indentation levels
- Copy-paste from sources with different indentation
- Wrong alignment after if/for/def
Fixes
- 1. Use spaces consistently (PEP 8: 4 spaces)
# Configure editor to use 4 spaces, never tabs
- 2. Convert tabs to spaces
expand -t 4 file.py > file_fixed.py
- 3. Check block alignment
def foo(): if True: pass # same indent level for block
Still not fixed?
- • Search the exact error message on Stack Overflow or GitHub Issues
- • Check the official docs for the language or tool
- • Ensure your versions (Node, Python, npm, Docker) are up to date
- • Try in a minimal reproduction (new project, single file)
Related Errors
DuskTools That Might Help
All Errors
JavaScript Heap Out of MemoryModuleNotFoundErrorAddress Already in UseCannot Find ModulePeer Dependency WarningCORS Policy BlockedTypeError: 'NoneType' Not SubscriptableMerge ConflictDocker Port Already AllocatedENOENT: No Such File or DirectoryKeyErrorMaxListenersExceededWarningRecursionErrorDetached HEAD StateEACCES: Permission DeniedValueErrorNo Space Left on DeviceERR_REQUIRE_ESMFileNotFoundError