python for语句不设置循环次数怎么用?
yang
2020-05-29 09:54:023931浏览 · 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自学网
关注公众号,随时随地在线学习