A, if determined
Role: like people make different behaviors for different situations.
Code block: the same indentation level code
The basic syntax:
A grammar
if Condition: Code 1 Code 2 Code 3
Syntax two
if Condition: Code 1 Code 2 the else : Code 1 Code 2
Three Grammatical
if Condition: Code 1 Code 2 elif conditions: Code 1 elif conditions: code 1 is the else : Code 1 # elif can use the N
Syntax four if nested
if Condition 1: if Condition 2: Code 1 Code 2 the else : code 1 is the else : Code 1
Two, while circulation
1. What is the cycle?
The cycle is repeated to do something
BREAK : directly out the entire loop
the Continue : the end of this cycle, to enter the next cycle
The basic syntax:
while 条件: code1 code2 code3 code4 code5
while nesting
while True: while True: break break
while also and if nested statement
while else:
If the normal end of the while loop, instead of using the break ended, will be the implementation of the sub-code else
Out while the two methods of loop
1. while using the inner loop break
2. while modifying the value of the loop condition the condition becomes a logic value False
Three, for circulation
The power of the for loop that does not depend on the index value.
The basic syntax
for the variable name in the type of container: Code 1, Code 2, Code 3, Code 4,
Container type: can accommodate a plurality of types of data can be obtained by a container type length len ().
ps: the difference in the range of Python2 and Python3
Python2 in
The return value is a list of 1.range
2.xrange is in the range Python3
Python3 the range is an iterator, get value when needed.