Home > Article > Backend Development > What is the use of indentation in python
Python is a very "unique" language!
why would you say so!
Because 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 pleasure; people who don’t like it say it is It is a language that requires calipers, because it is necessary to use a "vernier caliper" to measure the indentation of each line of code. (Recommended learning: Python video tutorial)
No matter what, the developers of Python intentionally prevent programs that violate the indentation rules from being compiled, so that Programmers 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 the method of indentation in Python!
Python’s indentation method
·Use the tab key
·Indent a few spaces (usually 4)
For example, the following example:
>>> if True: …… print("this is true") // …… print("this is true") // …… else: …… print("this is false")// …… print("this is false")// 输出结果: this is true this is true
It should be noted that although Python syntax allows code blocks to be indented by any number of spaces, all statements located in the same code block must maintain the same indentation and cannot be indented at once. Indent by 3 spaces and 4 spaces at a time.
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of What is the use of indentation in python. For more information, please follow other related articles on the PHP Chinese website!