indentationerror: unindent does not match any outer indentation level
- Indenting your code can be a messy business if you try to use both spaces and tabs.
- In Python, using both methods of indentation results in an error.
- This error is indentationerror: unindent does not match any outer indentation level.
- unindent does not match
- unindent does not match any outer indentation level
- python unindent does not match any outer indentation level
Spaces are the preferred method of indentation in Python but you can use tabs if you want.
import sys def get_factors(number): for i in range(1, number + 1): if number % i == 0: print("{} is a factor of {}.".format(i, number)) get_factors(4)
1 is a factor of 4 4 is a factor of 4 4 is a factor of 4
import sys def Factorial(n): # return factorial result = 1 for i in range (1,n): result = result * i print("factorial is ",result) return result Factorial(10) # factorial is 362880
Using Visual studio code
If you are using vs code than, it will convert all mix Indentation to either space or tabs using this simple steps below.
- Press Ctrl + Shift + p
- Type indent using spaces
- Press Enter
Python code can be indented with tabs or spaces. It’s up to you.Python only has an objection when you use both spaces and tabs to indent your code. Python requires you use only one method of indentation.
unindent does not match any outer indentation level
Conclusion
The indentationerror: unindent does not match any outer indentation level error is raised when you use both spaces and tabs to indent your code.To solve this error, check to make sure that all your code uses either spaces or tabs in a program.
References