Objective
Conquer all kinds of statements, customs can get brush jump to jump permission. (yes, there are eggs again)
"1" Python conditional statement
The Python conditional statement determines the execution block of the code through the execution result (true or false) of one or more statements, where any non-0 and non-null (NULL) values are true, 0, or null is false.
1) Single Condition judgment
Like in other languages, the if statement in Python is used for the execution of the control program, where the "judging condition" is established (not 0), then the subsequent statement executes, and the execution content can be multiple lines, in order to indent to differentiate the same scope. Else is an optional statement that executes when the content needs to be executed when the condition is not established. The basic form is shown in the following example:
If
2) Multi-conditional judgment
The judgment condition of the IF statement can be expressed by > (greater than), < (less than), = = (equals), >= (greater than or equal), <= (less than or equal). If there are multiple conditions, you can use parentheses to distinguish the order of judgment, the judgment in parentheses precedence, and the priority of and and or is lower than > (greater than), < (less than), such as the judgment symbol, that is, greater than and less than in the absence of parentheses will be compared with or priority to judge.
Elif
Because Python rejects the switch statement, so: multi-conditional judgment with elif, multi-criteria at the same time to determine the use of or (indicating that two conditions have a successful judgment condition), or and (indicates that only two conditions at the same time to establish a judgment condition is successful). So when judging a condition as multiple values , you can use the following form:
Multiple conditions
3) Note
The Python composite Boolean expression evaluates to a short-circuit rule, that is, if the value of the entire expression has been computed through the previous section, then the later part is no longer evaluated.
On the wrong.
"2" Python loop statement 1) loop type
No do. While loop whining
①python while Loop statement
The loop ends when the condition false false is judged.
Infinite Loop: If the conditional judgment statement is always true, the loop will be executed indefinitely.
CTRL + C can interrupt loops
style= Box-sizing:border-box"; Font-weight:bolder; " > rings Use the Else statement: in Python, while ... else executes an ELSE statement block when the loop condition is false
Simple Statement Group: syntax similar to the IF statement, if you have only one statement in the while loop body, you can write the statement in the same row as while.
②python for Loop statement
A Python for loop can traverse any sequence of items, such as a list or a string.
And while ... else, for ... else means that the statement in for is not the same as normal, and the statement in else executes when the loop is normally executed (that is, for not breaking out by break).
③ Loop Nesting
To embed another loop body in the loop, such as a For loop in a while loop, and conversely, you can embed a while loop in a for loop.
2) Loop control statement
"Judging condition" can also be a constant value oh, that the cycle must be set!
loop control statements can change the order in which statements are executed
①python Break statement
In the C language, the Python break statement breaks the minimum enclosing for or while loop. The break statement terminates the Loop statement, that is, the loop condition does not have a false condition, or the sequence is not fully recursive, and the loop statement is stopped.
If it is a nested loop, the break statement stops executing the deepest loop and starts executing the next line of code.
②python Continue statements
Jumps out of the entire while and for loops relative to break. Loop, the Python continue statement jumps out of the loop. The continue statement is used to tell Python to skip the remaining statements of the current loop, and then proceed to the next round of loops.
③python Pass Statement
The Python 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.
Eggs:
http://mp.weixin.qq.com/s?__biz=MjM5MzgyODQxMQ==&mid=2650367751&idx=1&sn= 461393c2cbd1d357bcb7cc5103ac2cd0&chksm= be9cdc5389eb55458d7733bfa787baa40996316625e610bfc86f84d4600077614895550523de&mpshare=1&scene=23& Srcid=0114f4e3ubhyluh2xhorvouu#rd
Life is short,you need python!| (3)