晴川云Python教程:python for语句不设置循环次数怎么用?

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'
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容