# What is unexpected indent in Python?

PythonServer Side ProgrammingProgramming

Python not only insists on indentation, it insists on consistent indentation. If we indent one line by 4 spaces, but then if we indent the next by 3 (or 5, 6, .), we get this error of unexpected indent in python.

In the given code, line 3 has more spaces at the start than line 2. All lines of code in a block must start with exactly the same number of spaces. Both print statements must be indented same number of spaces. So the corrected code that does not show unexpected indent is as follows.

def a():
print "foo"
print "baz"


Published on 07-Dec-2017 06:41:39