You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IndentationError: unexpected indent
IndentationError: expected an indented block
TabError: inconsistent use of tabs and spaces in indentation
Common Causes
Mixed tabs and spaces — most common cause of TabError
Wrong indentation level — indented too much or too little
Missing block body — empty if/for/while block without pass
Copy-paste with different indentation
Quick Fix
# Convert all tabs to spaces (4 spaces per tab)
expandtabs file.py > fixed.py
# Check for mixed tabs/spaces
python -m py_compile file.py
# Or use autopep8 to auto-fix
pip install autopep8
autopep8 --in-place file.py
Detailed Solution
Solution 1: Use Spaces (Not Tabs) Consistently
# ❌ Mixed tabs and spaces (TabError)defgreet(name):
print("Hello") # ← tabprint(name) # ← spaces# All spaces (4 per level is PEP 8 standard)defgreet(name):
print("Hello")
print(name)
Solution 2: Empty Blocks Need pass
# ❌ Syntax error — block can't be emptydeffuture_feature():
foriteminitems:
# Use pass as placeholderdeffuture_feature():
passforiteminitems:
pass