在Python中,* zip(list1,list2)返回什么类型的对象? [英] In Python what type of object does *zip(list1, list2) return?
本文介绍了在Python中,* zip(list1,list2)返回什么类型的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
Python: Once and for all. What does the Star operator mean in Python?
x = [1, 2, 3]
y = [4, 5, 6]
zipped = zip(x, y)
list(zipped)
x2, y2 = zip(*zip(x, y))
x == list(x2) and y == list(y2)
*zip(x, y)
返回什么类型的对象?为什么
What type of object does *zip(x, y)
return? Why
res = *zip(x, y)
print(res)
不起作用?
推荐答案
Python中的星号"operator"不会返回对象;这是一种语法结构,意思是以给出的列表作为参数调用函数."
The asterisk "operator" in Python does not return an object; it's a syntactic construction meaning "call the function with the list given as arguments."
所以:
x = [1、2、3]
f(* x)
x = [1, 2, 3]
f(*x)
等效于:
f(1、2、3)
与此相关的博客条目(不是我的): http://www.technovelty.org/code/python/asterisk.html
Blog entry on this (not mine): http://www.technovelty.org/code/python/asterisk.html
这篇关于在Python中,* zip(list1,list2)返回什么类型的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文