Python内置函数
- Python内置函数- __import__() 函数
- Python内置函数- zip()函数
- Python内置函数-vars()函数
- Python内置函数-type()函数
- Python内置函数-tuple 函数
- Python内置函数-super()函数
- Python内置函数-sum()函数
- Python内置函数-str()函数
- Python内置函数-staticmethod()函数
- Python内置函数-sorted()函数
- Python内置函数-slice()函数
- Python内置函数-setattr()函数
- Python内置函数-set() 函数
- Python内置函数-round()函数
- Python内置函数-reversed函数
- Python内置函数-repr()函数
- Python内置函数-range() 函数
- Python内置函数-property() 函数
- Python内置函数-print() 函数
- Python内置函数-pow() 函数
- Python内置函数-ord()函数
- Python内置函数-open()函数
- Python内置函数-oct() 函数
- Python内置函数-next() 函数
- Python内置函数-min() 函数
- Python内置函数-memoryview() 函数
- Python内置函数-max() 函数
- Python内置函数-map()函数
- Python内置函数-locals() 函数
- Python内置函数-list()函数
- Python内置函数-len()函数
- Ptyhon内置函数-iter()函数
- Python内置函数-issubclass()函数
- Python内置函数-isinstance() 函数
- Python内置函数-int() 函数
- Python内置函数-input()函数
- Python内置函数-id()函数
- Python内置函数-hex()函数
- Python内置函数-help()函数
- Python内置函数-hash() 函数
- Python内置函数-hasattr() 函数
- Python内置函数-globals() 函数
- Python内置函数-getattr() 函数
- Python内置函数-frozenset() 函数
- Python内置函数-format()函数
- Python内置函数-float()函数
- Python内置函数-filter()函数
- Python内置函数-exec()函数
- Python内置函数-eval()函数
- Python内置函数-enumerate() 函数
- Python内置函数-divmod()函数
- Python内置函数-dir()函数
- Python内置函数-dict()函数
- Python内置函数- delattr()函数
- Python内置函数-complex()函数
- Python内置函数-compile() 函数
- Python内置函数-classmethod()函数
- Python内置函数-chr() 函数
- Python内置函数-callable() 函数
- Python内置函数-bytes函数
- Python内置函数-bytearray() 函数
- Python内置函数-bool()函数
- Python内置函数-bin() 函数
- Python内置函数-ascii()函数
- Python内置函数-any() 函数
- Python内置函数-all() 函数
- Python内置函数-abs() 函数
- Python内置函数-大全
Python内置函数- zip()函数
Python3内置函数--zip()函数
zip()函数描述:
zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的对象,这样做的好处是节约了不少的内存。
我们可以使用 list() 转换来输出列表。
如果各个迭代器的元素个数不一致,则返回列表长度与最短的对象相同,利用 * 号操作符,可以将元组解压为列表。
zip()函数语法:
zip([iterable, ...])
zip()函数参数:
iterabl -- 一个或多个迭代器;
zip()函数返回值:
返回一个对象。
zip()函数实例:
list1 = [1,2,3,4] list2 = ['a','b','c','d'] list3 = ['i','am','here'] _list = zip(list1,list2,list3) print(type(_list)) # <class 'zip'> print(list(_list)) # [(1, 'a', 'i'), (2, 'b', 'am'), (3, 'c', 'here')] _list1 = [1,2,3] _list2 = [4,5,6,7] _list3 = [8,9,10,11,12] print(list(zip(_list1,_list2))) # [(1, 4), (2, 5), (3, 6)] 元素个数与最短的列表一致 print(list(zip(_list3,_list2))) # [(8, 4), (9, 5), (10, 6), (11, 7)] 元素个数与最短的列表一致
与 zip 相反,zip(*) 可理解为解压,返回二维矩阵式:
zip1 = [(1, 4), (2, 5), (3, 6)] a12 = zip(*zip1) a1, a2 = zip(*zip1) print(type(a12)) #<class 'zip'> print(list(a12)) # [(1, 2, 3), (4, 5, 6)] print(type(a1)) #<class 'tuple'> print(a1) # (1, 2, 3) print(list(a2)) # [1, 2, 3]
最后修改:2020年3月24日 13:14