将元组扩展为参数
有没有办法将Python元组扩展为函数 - 作为实际参数?
例如,这里expand()
有魔力:
tuple = (1, "foo", "bar")def myfun(number, str1, str2): return (number * 2, str1 + str2, str2 + str1)myfun(expand(tuple)) # (2, "foobar", "barfoo")
我知道可以定义myfun
为myfun((a, b, c))
,但当然可能有遗留代码。谢谢
DIEA
子衿沉夜
相关分类