How to record the number of loops in Python?
Related recommendations: "python video"
In the for loop of Python , the loop traversal can be written as:
for item in list: print item
It can iterate through all the elements in the list, but is there any way to know how many times I have looped so far?
The alternatives that come to mind are:
count=0for item in list: print item count +=1 if count % 10 == 0: print 'did ten'
or:
for count in range(0,len(list)): print list[count] if count % 10 == 0: print 'did ten'
The above is the detailed content of How to record the number of loops in Python. For more information, please follow other related articles on the PHP Chinese website!