1.for
# Iteration of the loop variable is a meaning
# the meaning of the elements of the list inside out is to walk
listvar = [ "One", "TWO", "Three", "at Four", "Five", "Six"]
# with len Get a list of length
RES = len (listvar)
Print (RES)
# (. 1) traversed while manner
I = 0
while I <len (listvar):
# "0. 1 2. 3. 4. 5"
RES = listvar
Print (RES)
=. 1 + I
setvar = [ "One", "TWO", "Three", "Four", "Five", "Six"]
#while cycle has its limitations, such is not possible to set the data type of the variable
# so for born cycle applications especially for the loop
I = 0
the while I <len (setvar):
RES = setvar [I]
Print (RES)
I =. 1 +
# (2) for syntax: for ..in ..
Code analysis:
the container type in which each element of the data, we study late iterator objects generator range
for variable objects in iterations:
Print (variable)
code analysis:
Each element of the container-type data categories, in order to come up with the assignment of the variable i
know all of the data is completed, traversing exit the loop
# traversing the list
container = [ "one", " two", "three", "four", "five "," Six "]
# traverse tuple
Container = (" One "," TWO "," Three "," Four "," Five "," Six ")
# through the collection
container = {" one "," two " , "Three", "Four", "Five", "Six"}
# dictionary traversal
container = { 'top': 'Juggernaut', 'middle': 'fox', 'bottom': 'Levin'}
# variable string
container = "I love you honey mushrooms cool, I'll see you flustered"
for i in container:
Print (i)
# (3) traversal long secondary containment
listvar = [( "Wang Lin" "Wang Sisi", "Wang Meili"), [ "Ma""Ma flower", "Mars"], [ "Vang Pao", "Marble", "Song Andy"]]
# unpacked variables
A, B = 1,2
Print (A, B)
A, B = [ 3,4-]
Print (A, B)
A, B = {5,6}
Print (A, B)
Print ( "7777777777777777777777777777")
A for, b, c in listvar:
"" "
A, b, c (" Wang Lin "," Wang Sisi "," Wang Meili ")
A, b, c [" Ma "," Ma flower "," Mars "]
A, B, C [" Vang Pao "," Marble "," Song Andy "]
" ""
Print (A, B, C)
listvar = [(1,2), [3,4-], [. 5 ,. 6]]
for a, B in listvar:
Print (a, B)
# (. 4) traversing the two unequal container
listvar = [( "Wang Lin", "Wang Sisi") [ "Ma flower", " Ma Meili "], [" Vang Pao, "" Song Xiao Bao "]]
for i in listvar:
for i in J:
Print (J)
# (5) the Range Object
# syntax:
the Range (Start, End, the STEP)
Start:Start value
end: end value
step: step
similar slice syntax and use, the upper end is less than that value is taken, that value is taken prior to the end
where # is a parameter range (5) => 0 1 2 3 4 Default high 5 fail to zero, to get the maximum. 4
Print (Range (5), type (RES))
RES = List (Range (5))
Print (RES)
for I in Range (. 5):
Print (I)
# 2 case where parameters
for I in Range (3,10):
Print (I)
# (case 33 parameters 246810
# n sequence
for I in Range (2,11,2):
Print (I)
# reverse
# ~ print. 1. 9. 8. 7. 9. 6 2. 5. 4. 3. 1
for I in Range (9,0, -1):
Print (I)
2. Keywords: break pass continue
# (1) pass through the action: do placeholder
IF. 5 ==. 5:
Pass
I = 0
the while I <10:
Pass # convention, in the case where nothing inside the loop line, given this greeting
I =. 1 +
# ( 2) break terminates the current cycle (cycle for which only)
'' 'Print 1-10, the loop is terminated if the face 5' ''
I = 1
the while I <= 10:
IF I == 5:
BREAK
Print (I )
I + =. 1
#break terminates the current cycle, one outside the loop, there three cycles, but when j = 3, when the loop termination
I =. 1
the while I <=. 3:
J =. 1
the while J <=. 3:
iF J . 3 ==:
BREAK
Print (I, J)
J. 1 + =
I + =. 1
# 3,2- 3,1 1,1 1,2 2,1 2,2 &
# (. 3) Continue to skip the current cycle, the cycle from start
# 1 10 does not print the print. 5
I = 1
the while I <= 10:
==. 5 I IF:
I = 1 + # After careful skip cycle behind the code is not executed, the execution starts from the circulation
Continue
Print (I, End = "") print a line and space it #
I = 1 +
# printing all free numbers 1 to 100 4
# Analysis:
98 If you remove the ten-digit number 98, and
8 => 98% = 10> 8
9 => 98 @ 10 => 9
// can be obtained by a number of other high-floor
by taking the remainder may be acquired% a lower number
# first method
I =. 1
the while I <100:
IF I //. 4 or 10 == I == 10%. 4:
I + =. 1
Continue
Print (I)
I =. 1 +
# second method
. 1 = I
the while I <= 100:
NUM = STR (I)
IF '. 4' in NUM:
I + =. 1
Continue
Print (I)
I + =. 1