everyone all know that Python is a language that is very sensitive to indentation, the code format is very strict, the personal encounter Some of the most common problems are as follows:
1. Spaces or tabs should not be used where spaces or tab indents are used
2. Different levels of code are not indented
3. The indent quantity is not correct
3.1 Code all use 4 spaces, some code indent is not 4 spaces
3.2 Indent Too much (this should be 4 spaces or 1 tabs, indent 8 spaces or 2 tab) or too little (this should be 8 spaces or 2 tab, indent 4 spaces or 1 tab)
4.themix of tab and space-----The problem is most ugly .
These errors are difficult to discern with the naked eye ...
Error message: indentationerror:unexpected indent;indentationerror:expected an indented block ...
If you encounter this kind of error, It could be the tab and space indentation in the code, and you need to check the tab and space. "
"Solution"
1. Check if a space or tab should not be used, check for indentation, whether the indent is aligned, indent, and whether the space is mixed
2. Annotations are sometimes affected, so the indentation of annotations should also be noticed
3. In particular , if indentation and whitespace are mixed , you can use the text editor notepad++ to display all the spaces or tab characters of the current Python script.
settings See:
Show spaces and tabs, display symbols, view
Tips:
Make sure that you use 4 or 4 of multiple spaces within your code, or use the TAB key or more than one tab key, and if you run without it, you can use Pycharm to run, and the error message will tell you exactly which line is wrong.
Summary of whitespace and indentation issues in Python