python中如何记录循环次数?
相关推荐:《python视频》
在Python的for循环里,循环遍历可以写成:
for item in list: print item
它可以遍历列表中的所有元素,但是有什么方法可以知道到目前为止我循环了多少次?
立即学习“Python免费学习笔记(深入)”;
想到的替代方案是:
count=0for item in list: print item count +=1 if count % 10 == 0: print 'did ten'
或:
for count in range(0,len(list)): print list[count] if count % 10 == 0: print 'did ten'
以上就是Python中记录循环次数的方法的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号