码迷,mamicode.com
首页 > 编程语言 > 详细

Python 循环

时间:2019-03-27 00:18:00      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:pytho   clu   code   python   zip   index   clust   class   循环   

循环
range实现循环

S = [1, 2, 3, 4, 5, 6]

for i in range(0, len(S), 2):
    print S[i]

enumerate 实现循环

S = [10, 20, 30]

for (index, value) in enumerate(S):
    print index
    print value

zip

ta = [1, 2, 3, 4]
tb = [9, 8, 7]
tc = ['a', 'b', 'c']
for (a, b, c) in zip(ta, tb, tc):
    print(a, b, c)

'''
(1, 9, 'a')
(2, 8, 'b')
(3, 7, 'c')
'''
ta = [1, 2, 3]
tb = [9, 8, 7]

# cluster
zipped = zip(ta, tb)
print(zipped)

# decompose
na, nb = zip(*zipped)
print(na, nb)
'''
[(1, 9), (2, 8), (3, 7)]
((1, 2, 3), (9, 8, 7))
'''

Python 循环

标签:pytho   clu   code   python   zip   index   clust   class   循环   

原文地址:https://www.cnblogs.com/jiqing9006/p/10604668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!