classzip(object)|zip(*iterables)--> A zipobject yielding tuples until an inputis exhausted.||>>>list(zip('abcdefg',range(3),range(4)))|[('a',0,0),('b',1,1),('c',2,2)]|| The zipobject yields n-length tuples, where n is the number of iterables
| passed as positional arguments to zip(). The i-th element in every tuple| comes from the i-th iterable argument to zip(). This continues until the
| shortest argument is exhausted.
说明:
"""
类 zip(对象) | zip(iterables) --> 一个 zip 对象产生元组,直到输入用尽。
| | >>> list(zip('abcdefg', range(3), range(4)))
| [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)]
| | zip 对象产生 n 长度的元组,
其中 n 是可迭代的数量 |作为位置参数传递给 zip()。
每个元组中的第 i 个元素 |来自 zip() 的第 i 个可迭代参数。
这种情况一直持续到 |最短的论点已用尽。
返回元组的迭代器,其中第i个元组包含来自每个参数序列或可迭代对象的第i个元素。
当最短的输入迭代用完时,迭代器停止。使用单个可迭代参数,它返回一个 1 元组的迭代器。
没有参数,它返回一个空的迭代器
并行迭代几个可迭代对象,生成元组,每个对象都有一个项目。
Python 的zip()函数定义为zip(*iterables).
该函数将可迭代对象作为参数并返回一个迭代器。
此迭代器生成一系列元组,其中包含来自每个可迭代对象的元素。
zip()可以接受任何类型的可迭代对象,例如文件、列表、元组、字典、集合等。
"""
举例
'相当于合并每个可迭代类型的对应索引值''不同的数据类型均可以''当最短的输入迭代用完时,迭代器停止,例如下文中的字典到4,到3的区别'
res =list(zip('1234',(111,222,333,444),range(4),{"1":1,"2":2,"3":3,"4":4}))
res1 =list(zip('1234',(111,222,333,444),range(4),{"1":1,"2":2,"3":3}))# res = help(zip)print(res)# [('1', 111, 0, '1'), ('2', 222, 1, '2'), ('3', 333, 2, '3'), ('4', 444, 3, '4')]print(res1)# [('1', 111, 0, '1'), ('2', 222, 1, '2'), ('3', 333, 2, '3')] 这里就少了一个值.'使用zip函数将返回一个生成长度元组的迭代器n''解迭代器,使用list,tuple均可,使用[],()不行''迭代器可以使用for 循环获取数据'
res =zip('1234',(111,222,333,444),range(4),{"1":1,"2":2,"3":3,"4":4})print(res)# <zip object at 0x000002B3B3BD9380>
res =tuple(res)print(res)