我试图做类似下面的操作:将多个参数传递给一个函数?
a = 2
b = 4
c = 6
def my_function(a,b,c):
a1 = a*2
b1 = b*2
c1 = c*2
return (a1,b1,c1)
x = my_function(a,b,c)
my_function(x)
在哪里,我想反复调用my_function()
自身的输出是否符合一定的条件。
不过,我得到的结果:
TypeError: my_function() missing 2 required positional arguments: 'b' and 'c'
我相信这是一个基本的问题,并已在别处回答,但它似乎很简单,这是很难寻找。
使用'my_function(* x)'使'x'-tuple *爆炸*并创建与它包含的元素一样多的输入。 –
'my_function(* x)' - 见https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists – khelwood