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

How does Python divide statement blocks?

藏色散人
Release: 2019-07-01 09:11:47
Original
12336 people have browsed it

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")
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template