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')