How does Python divide statement blocks?
Python divides statement blocks through indentation format. Statements are the basic building blocks in programming.
Python statements and statement blocks, indentation
Python statements are different from programming languages such as C. There is no need to add a semicolon at the end of a Python statement to indicate the end of the statement, just wrap it in a new line. Another very important point is to use indentation to indicate the logical relationship between statement blocks instead of braces. These two features not only maintain code readability, but also reduce symbol input and improve efficiency. Lazy people love
Python indentation
The number of indented spaces is variable , but the corresponding statements in the unified code block must be consistent, otherwise an error will be reported. In the example code below, an error will occur due to inconsistent indentation.
if True: print ("True") else: print ("else") print ("have a try")
Related recommendations: "Python Tutorial"
The above is the detailed content of How does Python divide statement blocks?. For more information, please follow other related articles on the PHP Chinese website!