1. Cycle & Condition Control
Note:
-
-
Each condition is followed by a colon (:), which represents the next block of statements to be executed after the condition is met.
Using indentation to divide a statement block, a statement with the same indent number together makes up a block of statements.
The break statement can jump out of a for and while loop body.
The continue statement is used to tell Python to skip the remaining statements in the current loop block and proceed to the next round of loops.
Pass is an empty statement in order to maintain the integrity of the program structure. Pass does not do anything, generally used as a placeholder statement.
Cycling Tips:
-
-
When looping through a dictionary, keywords and corresponding values can be interpreted simultaneously using the items () method
when looping through a sequence, the index position and the corresponding value can be used Enumerate () functions are also
To loop two or more sequences at the same time, you can use zip () Overall Packaging
If a reverse loop sequence is required, the sequence is positioned first and then called reversed () function
Operator |
Describe |
< |
Less than |
<= |
Less than or equal to |
> |
Greater than |
>= |
Greater than or equal to |
== |
Equals, compares objects for equality |
!= |
Not equal to |
2. Functions
Attention:
-
The function code block begins with a def keyword followed by the function identifier name and parentheses ().
Any incoming parameters and arguments must be placed in the middle of the parentheses, and the parentheses can be used to define the parameters.
The first line of the function statement can optionally use the document string-for storing the function description.
The function contents begin with a colon and are indented.
return [expression] ends the function, optionally returning a value to the caller. Return without an expression is equivalent to returning None.
Function call:
def function (str): ' Print any incoming string ' (function description) print (str) return ' OK ' function (' I want to invoke this custom function ') (function call) function (' Call again ')
This article is from the "unplug the Operational Space" blog, please be sure to keep this source http://zhangdj.blog.51cto.com/9210512/1881436
Python3_04. Loops & Functions