Home >Backend Development >Python Tutorial >How does Python divide statement blocks?

How does Python divide statement blocks?

藏色散人
藏色散人Original
2019-07-01 09:11:4712366browse

How does Python divide statement blocks?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn