python中zip函数

时间:2021-05-04 15:19:44   收藏:0   阅读:0

python中zip函数

1、python中zip函数用于返回由可迭代参数共同组成的元组。

 

长度不一致时,以短的序列进行迭代。

>>> test1 = ["aaa","bbb","ccc","ddd"]
>>> test2 = (111,222,333,444,555)
>>> test3 = "abcde"
>>> for i in zip(test1, test2):
    print(i)

    
(aaa, 111)
(bbb, 222)
(ccc, 333)
(ddd, 444)
>>> for i in zip(test1,test3):
    print(i)

    
(aaa, a)
(bbb, b)
(ccc, c)
(ddd, d)
>>> for i in zip(test1,test2,test3):
    print(i)

    
(aaa, 111, a)
(bbb, 222, b)
(ccc, 333, c)
(ddd, 444, d)

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!