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

How to record the number of loops in Python

爱喝马黛茶的安东尼
Release: 2019-06-17 16:44:23
Original
13059 people have browsed it

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
Copy after login

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'
Copy after login

or:

for count in range(0,len(list)):
    print list[count]
    if count % 10 == 0:
        print 'did ten'
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template