Home python Tell me why at startup it swears at “IndentationError: unindent does not...

Tell me why at startup it swears at “IndentationError: unindent does not match any outer indentation level”





File "/tmp/sessions/76bc0639bb20652b/main.py", line 4
print ('Hello,', name, '!')
........................................ ^
IndentationError: unindent does not match any outer indentation level

On the advice, I re-filled the indents with tabs again, everything worked. Thanks to all!
Tell me how to mark a comment with a solution to the question?

Answer 1, authority 100%

In order to copy the “original” whitespace characters from the question, press edit and select and copy the text from the text field.

I pasted this text into Notepad ++:

From this it follows that somewhere you entered a tab character, and somewhere ordinary spaces. For the code to work, the indentation in the method must be the same. In your case, either 4 spaces or a tab character.

Additional information About Indentation in Python Code (PEP 8)

Tabs or spaces?

Spaces are the preferred indentation method.

Tabs should only be used to support tab-indented code.

Python 3 disallows mixing tabs and spaces in indentation.

Python 2 is trying to convert tabs to spaces.

When you invoke the Python 2 interpreter on the command line with the -t option, it will issue warnings when using
mixed style in indentation, and by running the interpreter with the parameter
-tt, you will get errors in these places. These options are highly recommended!

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions