2

Or equivalently, to pass multiple arguments to a called function?

So I am trying to do:

  1. define a function fun1
  2. define another function fun2, which will call fun1 but only assigning some values to fun1, with other values being assigned otherwise; or maybe I can assign multiple arguments to a called function?
def fun1(x, y):
    return x*y

def fun2(fun, x):
    print(fun(x))

fun2(fun1(y=2), 3) # doesn't work
fun2(fun1, (3, 2)) # doesn't work either

So how should I do this? I want fun2 to just print fun1's result with some variable for x (here I choose it to be 3) and assigned(fixed) y=2

coding_guy
  • 21
  • 2

1 Answers1

2

As suggested by @kaya3 Use python's variable *args feature.

IDLE :

>>> def fun1(x, y):
        return x * y

>>> def fun2(fun, x):
        print(fun(*x))


>>> fun2(fun1, (3, 2))
6
gsb22
  • 2,112
  • 2
  • 10
  • 25