作用:将几个等长的序列,每次对位取元素------合并成新的元祖
适用于:等长序列
演示:
>>> a = "wer"
>>> b = "jkl"
>>> c = zip(a, b)
>>> list(c)
[('w', 'j'), ('e', 'k'), ('r', 'l')]
>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> zip (a, b)
<zip object at 0x000002519D691808>
>>> list(zip(a, b))
[(1, 4), (2, 5), (3, 6)]
>>> a = "wer"
>>> b = "jkl"
>>> c = zip(a, b)
>>> list(c)
[('w', 'j'), ('e', 'k'), ('r', 'l')]
>>> for (x, y) in zip(a, b):
... print(x, y)
...
w j
e k
r l