close

[Solved] IndentationError: unexpected indent

I am trying to run simple python code But I am facing the following error: IndentationError: unexpected indent. In this Exerror article, We are going to learn about How to reproduce this error and we will discuss All Possible Solutions Lets Get Start with This Article.

How IndentationError: unexpected indent Error Occurs?

I am trying to run simple python code But I am facing the following error.

if len('myname') == 6:
    print('6 caharacter')
     print('worked')

But I am facing the following error.

    print('worked')
IndentationError: unexpected indent

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve IndentationError: unexpected indent Error?

  1. How To Solve IndentationError: unexpected indent Error?

    To Solve IndentationError: unexpected indent Error If You are using VS code then You need to use Code Formatter it will adjust your code by some shortcuts Or it will Give You an error. And Just removing extra spaces will resolve your error.

  2. IndentationError: unexpected indent

    There are two print statements in your code first one is Fine But the second one is having extra space and that's causing IndentationError To Solve IndentationError: unexpected indent Error You just need to have to remove unnecessary space or tab before it and your error will be solved. By removing extra space or tab your error will be resolved. Thanks.

Solution 1: Remove extra spaces

There are two print statements in your code first one is Fine But the second one is having extra space and that’s causing IndentationError To Solve IndentationError: unexpected indent Error You just need to have to remove unnecessary space or tab before it and your error will be solved.

if len('myname') == 6:
    print('6 caharacter')
    print('worked')

OUTPUT

6 caharacter
worked

By removing extra space or tab your error will be resolved. Thanks.

Solution 2: Use Code Formatter

If You are using VS code then You need to use Code Formatter it will adjust your code by some shortcuts Or it will Give You an error Just like this.

And Just removing extra spaces will resolve your error.

Conclusion

It’s all About this error. I hope We Have solved Your error. Comment below Your thoughts and your queries. Also, Comment below on which solution worked for you.

Also, Read

Leave a Comment