Home >Backend Development >Python Tutorial >How to record the number of loops in Python

How to record the number of loops in Python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-15 17:35:2413064browse

How to record the number of loops in Python?

Related recommendations: "python video"

How to record the number of loops in Python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn