zip() 可以接受多于两个的序列的参数。这时候所生成的结果元组中元素个数跟输入序列个数一样
>>> a = [1, 2, 3] >>> b = [10, 11, 12] >>> c = ['x','y','z'] >>> for i in zip(a, b, c): ... print(i) ... (1, 10, 'x') (2, 11, 'y') (3, 12, 'z') >>>
zip() 会创建一个迭代器来作为结果返回,需要将结对的值存储在列表中,要使用list() 函数
>>> zip(a, b) <zip object at 0x1007001b8> >>> list(zip(a, b)) [(1, 10), (2, 11), (3, 12)] >>>