Iteration (Iteration)
To judge an object to iterate:
1. You can traverse through the for loop
2. Judging by the iterable type of the collections module
What if you want to implement subscript loops like Java for a list:
Python's built-in enumeration method, enumerate, turns a list into an index-element pair
List-Generated
The result of the For loop output (after all integers in output 1-10 are squared):
in [+]: [i**2 for I in Range (1,11)]
OUT[41]: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
For Loop +if statement (all integers between output 1-10 squared, followed by 2 with the result of 0):
In [all]: [i**2 for I in range (1,11) if (i**2)%2==0]
OUT[42]: [4, 16, 36, 64, 100]
For loop +for loops (full array of output ' abc ' and ' 123 '):
in [+]: [I+j for I in ' ABC ' for j in "123"]
OUT[46]: [' A1 ', ' A2 ', ' A3 ', ' B1 ', ' B2 ', ' B3 ', ' C1 ', ' C2 ', ' C3 ']
Python (eight) advanced features