python branch circulation

1. traversal cycle

for i in range(5)
for i in range (M,N,K)
for c in s:
for c in 'python'
  print(c,end="")
for i in fi :  #系统打开文件

2. Wireless circulation

the while C> 0: 
    statement block

3.break与continue

BREAK : end the current cycle structure, into the back of the loop statements (single-layer)
 the Continue : When the end times behind the content of the loop and continue to re-enter the loop

 

= S ' Python ' 
the while S =! "" :
     for C in S:
         Print (C, End = "" ) 
    S = S [: -. 1]   # from the front to take off the first to the last, but not including a final 

# output is: pythonpythopythpytpyp 

S = ' Python ' 
the while S =! "" :
     for C in S:
         IF C == " T " :
             BREAK 
        Print (C, End = "" ) 
    SS = [: -. 1 ] 

# output is: pypypypypyp

4. cycle and senior cycle else

  else: normal exit loop "," bonus ", that is not executed break

for ( the while ):
     <statement>
 the else :
 # statement if not break, else part will be performed 
for C in  ' pyYhon ' :
     IF C == ' T ' :
         BREAK 
    Print (C, End = '' )
 the else :
     Print ( ' \ n-string there is no T ' )

 

Guess you like

Origin www.cnblogs.com/xdd1997/p/11707517.html