您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页python for语句不设置循环次数怎么用?

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'

更多Python知识请关注

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务