IndentationError: unindent does not match any outer indentation level IndentationError: unindent does not match any outer indentation level python python

IndentationError: unindent does not match any outer indentation level


Other posters are probably correct...there might be spaces mixed in with your tabs. Try doing a search & replace to replace all tabs with a few spaces.

Try this:

import sysdef Factorial(n): # return factorial    result = 1    for i in range (1,n):        result = result * i    print "factorial is ",result    return resultprint Factorial(10)


IMPORTANT:Spaces are the preferred method - see PEP008 Indentation and Tabs or Spaces?. (Thanks to @Siha for this.)

For Sublime Text users:

Set Sublime Text to use tabs for indentation:View --> Indentation --> Convert Indentation to Tabs

Uncheck the Indent Using Spaces option as well in the same sub-menu above.This will immediately resolve this issue.


To easily check for problems with tabs/spaces you can actually do this:

python -m tabnanny yourfile.py

or you can just set up your editor correctly of course :-)