晴川云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'

原创文章,作者:晴川运维,如若转载,请注明出处:https://baike.qcidc.com/5106.html

(0)
晴川运维晴川运维
上一篇 2025年6月8日
下一篇 2025年6月8日

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注