for x in ...
A loop is a statement that puts each element into a variable and x
then executes the indented block .
Note: Formatting in Python also acts as a syntax rule, and indenting a block is an example
summation problem, comparison and similarity 1/
Sum=0 forXinch[1,2,3,4,5,6,7,8,9,Ten]: Sum=sum+The xprint (sum) #此行无缩进, which indicates that the print command is not executed until the FOR Loop statement is finished, that the so-called "indent block" is the rule of the Python syntax, that the indentation is part of the For loop, and that no indentation jumps out of the For loop (or jumps out of the previous syntax) >>> -----------------------------2/
Sum=0 forXinch[1,2,3,4,5,6,7,8,9,Ten]: Sum=sum+With the x print (sum) #此处print有和上一行sum一样的缩进, the Py considers the line to be part of the indent block, and then executes the syntax rule, which loops 10 times with the sum of the print. >>>1 3 6 Ten the + - $ $ -
Python "code writing format" equivalent "syntax format", indentation and other habits can not be used, such as HTML and other grammar in order to look at the white space, tab and other habits will be strictly forbidden, perhaps one of the achievements of Python is to write code is very regular, not too many personal randomness.
Python Learning Notes (6)--for...in &while