1) range () control for Loop, Len () returns the number of objects
A='asfefqfq' for in range (0,len (a), 2): Print a[ b
How do I get it out of line output (Python2 directly in a[b] after adding a comma)
2) Enumerate () can get subscripts and elements from the loop
A='asfefqfq' for in Enumerate (a): Print (x, y),
3) Zip () extracts one element from a sequence of equal lengths and then makes up a new sequence
A='abc'b={1,2,3} for in Zip (b): Print C,
Use the * to untie C, almost a restore operation (A1,A2) =zip (*c)
4) Loop Object
A loop is an object with a next () method, for example, when a for loop is invoked, the next () method is called until Stopiteration appears, the For loop is accepted, the for loop ends, and the call is stopped.
for in open ("log.txt","R"): Print Line
5) iterators
There is also an object between the loop object and the For loop call, which needs to be performed with an iterator (iterator)
6) Generator
The generator (generator) is a user-defined loop object that, when writing and defining a function, converts return to yield, and each time it is removed using this method or loop, it starts from the point where it was last paused.
def KKK (): a=1 yield a =2 b=3 yield A * b yield KKK () :print x
Further understanding of generator expressions:
g= (x for X in range (4))
7) Table Inference
Table inference is a way to quickly generate a table (list comprehension)
Q=[] for in range (5): q.append (x**2)print Q
X1=[1,3,5]y1=[9,12,13]l=[x**2 for (x, y) in zip (x1,y1) if Y>10]print L
Mechanism to be understood? _?
Python Learning Diary