相关疑难解决方法(0)

2149
推荐指数
17
解决办法
65万
查看次数

将元组扩展为参数

有没有办法将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")
Run Code Online (Sandbox Code Playgroud)

我知道可以定义myfun为myfun((a, b, c)),但当然可能有遗留代码.谢谢

python tuples parameter-passing

375
推荐指数
5
解决办法
20万
查看次数

如何在python中将元组元素作为参数传递给函数?

我有一个由元组组成的列表,我想将每个元组的元素作为参数传递给函数:

mylist = [(a, b), (c, d), (e, f)]

myfunc(a, b)
myfunc(c, d)
myfunc(e, f)
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

最好的祝福

python arguments tuples list

12
推荐指数
1
解决办法
2万
查看次数