Home >Backend Development >Python Tutorial >What are Python indentation rules_Introduction to Python indentation rules
1. First of all, general languages use {} or end as a mark for code blocks, while Python identifies code blocks through indentation. Regarding Python’s [indentation] style, people who like it say it is a kind of fun; people who don’t like it say it is a language that requires calipers, because it is necessary to use a [cursor caliper] to measure the indentation of each line of code. Enter. In any case, Python developers intentionally prevent programs that violate indentation rules from being compiled so that programmers can develop good programming habits. And the Python language uses indentation to indicate the beginning and exit of statement blocks instead of using {} or other characters. Today I will briefly introduce to you how to indent in Python! Python's indentation method: use the tab key and indent a few spaces (usually 4), such as the following example:
2, and then the output result:
3. Finally, it should be noted that although Python syntax allows code blocks to be indented by any number of spaces, all statements in the same code block must maintain the same indentation and cannot be indented by 3 spaces at once. spaces, indent 4 spaces at a time.
The above is the detailed content of What are Python indentation rules_Introduction to Python indentation rules. For more information, please follow other related articles on the PHP Chinese website!