What is unexpected indent in Python?\\\


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"

Updated on: 26-Sep-2019

411 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements