有没有办法将Python元组扩展为函数——作为实际参数?
举个例子,这里的expand()
有魔力:
some_tuple = (1, "foo", "bar")
def myfun(number, str1, str2):
return (number * 2, str1 + str2, str2 + str1)
myfun(expand(some_tuple)) # (2, "foobar", "barfoo")
我知道可以将myfun
定义为myfun((a, b, c))
,但当然可能存在遗留代码.