Unexpected Indent Error Python

In this blog post, we will try to tell our users how they can solve one of the most common errors in python that may have faced a couple of times. This error is better known by the name unexpected indent error python. You have an indentation mistake, as the error message suggests. This error happens when a statement has an extra indentation or when the indentation of that statement differs from the indentation of earlier statements in the same block. Python demands consistent indentation in addition to the indentation at. Although you are allowed to decide how many spaces to use for indentation, you must utilize those spaces consistently. You’ll see this mistake if you indent one line by 4 spaces and the next by 2 (or 5, or 10, or…).

 

 

 

Solution of unexpected indent error python

The basic solution to this problem is that one should provide uniform spacing in python while writing the code. By uniform spacing, we mean a uniform level of indentation. The illustration of the same is also here:

 

def add(a, b):
# uniform indentation
    print(a, b)
    return a+b
print(add(5,4))

 

 

As one can see the indentation in this code is all of the same spacing. The output is as follows:

Output:

 

 

 

 

Also Read: Scalar Multiplication in Python

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *