In Python, indentation isn’t decoration — it’s the structure. Spaces at the start of a line decide which block the line belongs to. “Unexpected indent” means a line is indented in a way that doesn’t line up with any block: almost always mixed tabs and spaces (which can look identical on screen), or a block pasted in at the wrong level.
if, for, def or try without the body indented to match, or vice versa.if x: that isn’t indented, or a block header with nothing under it, surfaces as an indentation error nearby — an empty block needs a pass line.If the file looks perfectly aligned and still fails, suspect invisible characters from a copy-paste (non-breaking spaces from web pages are a known culprit). Retyping the offending lines by hand — not copying them again — clears what your eyes can’t see.
Can I mix tabs and spaces if it looks aligned? No. Python 3 raises an error for inconsistent mixing, and even where it parses, a tab counts differently in different editors — the file that looks right can be structurally wrong. Pick spaces and let the editor enforce it.
Why does the error point at a line that looks fine? Python reports where it noticed the structure break, which is the first line that doesn’t fit — the actual mismatch (an earlier block at the wrong level) can be several lines above.