1. Indent
Python uses the TAB key to differentiate the logic of the Code, that is, indentation, which is equal to four spaces in one indent
2.if conditions
Format:
If judging condition:
EXECUTE statement ...
Elif:
Execute statement ...
else:
Execute statement ...
Example:
A = Ten
B = -
if a>b:
Print("a>b")
elif a<b:
Print("a<b")
Else :
Print("a=b")
3.while Cycle
Format:
While judging condition:
EXECUTE statement ...
Example:
A = 3
while a> 0 :
Print("1111")
a-= 1
4.for Cycle
Format:
For Iterating_var in sequence:
Statements (s)
Example:
list1= [] Span style= "Font-size:12px;font-family:simsun, Stsong;color:rgb (0,0,255); Background-color:rgb (255,255,255);" >1 Span style= "Font-size:12px;font-family:simsun, Stsong;color:rgb (0,0,255); Background-color:rgb (255,255,255);" >3 Span style= "Font-size:12px;font-family:simsun, Stsong;color:rgb (0,0,255); Background-color:rgb (255,255,255);" >4 Span style= "Font-size:12px;font-family:simsun, Stsong;color:rgb (0,0,255); Background-color:rgb (255,255,255);" >2 "
for a inch List1:
Print(a)
Common methods:
1) Enumerate: subscript and corresponding value
Example:
Dict1 =Dict(a=1,b=2,C=3,D=4)
for key1, value1 in Enumerate ( DICT1):
Print(key1,value1)
2) print (range (1,10)): Print all at once 1-10 (memory)
Example:
Print (range(1,ten))
3) Print (xrange (1,10)): Print 1-10 on call
Example:
forIinchxrange(1,Ten):
Print (i)
Example:
xrange ( 1 10
Print (i)
Print List (i)
5.break and Continue termination
1) Continue: Jumps to the beginning of the next cycle
Example:
forIinchxrange(1,6):
If i = = 3:
Continue
Print ("i=%d" % i)
2) Break: Jump out of the loop
Example:
forIinchxrange(1,6):
If i = = 3:
break
Print ("i=%d" % i)
Python conditions, loops, termination