The most distinctive feature of Python is the code that is labeled as a block in indentation.
below we use the IF selection structure example, if followed by the condition, if the condition is true, then execute a block of code that belongs to the if
look first . C the way of language expression
if (i>0) { x=1; Y=3;}
if i>0 , we will carry out the two assignment statements that are included in parentheses. The parentheses contain the block operation, which is subordinate to the if
same purpose, in python , this passage is like this.
if i>0: x=1 y=3
in python , remove the parentheses around the i>0 , remove the semicolon at the end of each statement, and the curly brace of the block disappears. Extra :( colon ), as well as the indentation of the preceding four spaces in the x=1 and y=3 statements, by indenting python recognizes these two statements when they are subordinate to the if. The reason Python is designed to look good and simple for the program
Summarize:
the indentation of the preceding four spaces in the statement indicates an affiliation, andPython cannot be indented
if < conditions 1>: statementelif < conditions 2>: statementelif < conditions 3>: statementElse: statement
while i>0: x=2 y=3 while x==2: Print( " Hello ")
The 16th lesson in Python Learning--indentation (indentation)