python中列表-元组转换问题,zip(),tuple(),list()函数功能与示例

zip():打包为元组的列表

a=[1,2,3]
b=[4,5,6]
zip(a,b)
[(1, 4), (2, 5), (3, 6)]

tuple():将列表转换为元组

tuple([1,2,3,4])
(1, 2, 3, 4)

tuple((1,2,3,4))
(1, 2, 3, 4)

tuple(zip(a,b))
((1, 4), (2, 5), (3, 6))

list():将元组转换为列表

list(tuple(zip(a,b)))
[(1, 4), (2, 5), (3, 6)]

猜你喜欢

转载自blog.csdn.net/weixin_41824534/article/details/108453515