品易云推流 关闭
文章详情页
文章 > Python常见问题 > python for语句不设置循环次数怎么用?

python for语句不设置循环次数怎么用?

头像

yang

2020-05-29 09:54:023122浏览 · 0收藏 · 0评论

在Python的for循环里,循环遍历可以写成:

for item in list:
    print item

它可以在不设置循环次数的情况下遍历列表中的所有元素。

我们可以使用下面的方法统计循环的次数:

count=0
for item in list:
    print item
    count +=1
    if count % 10 == 0:
        print 'did ten'

更多Python知识请关注Python自学网

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图