1. For loop: The user iterates through the contents of the object sequentially
Format: For variable in object: (during traversal, assign element one by one in the object to the variable)
s = ' python ' for item in S: print (item) Result: Python
2. Enumerate: Add serial number for the iterated object
s = ' python ' for i,v in Enumerate (s): print (I,V) results: 0 p1 y2 t3 h4 o5 N
As shown above, each access string s an element adds a serial number to the element
3. Range: Generates the specified number within the specified range
There are three parameters: Start (start position), stop (as of position +1), step (digital spacing)
Three different forms:
1, Range (stop): Indicates the range from 0 to stop-1, the next number is the previous number plus 1 (only one parameter, the range by default from zero to the parameter stop-1, the step is the default of 1)
2, Range (Start,stop): Indicates that the range is start to stop-1, the next number is the last digit plus 1
3. Range (Start,stop,step): Indicates the range is start to stop-1, the next number is the previous digit plus step
Note: The corresponding number is created only when the number is called
Print (range) for I in range: print (i) Results: Range (0, 10) 0123456789
The direct output range is a range (0, 10) that does not create a number, and it creates a number only after each subsequent for loop executes once.
Python3 for Loop, Enumerat, range