I have defined a two-variables function like
def f(x1, x2):
return x1 + x2
Now, I want to pass a series of x2
into function f
without calling it, to create a series of new functions. How can I achieve that?
I have defined a two-variables function like
def f(x1, x2):
return x1 + x2
Now, I want to pass a series of x2
into function f
without calling it, to create a series of new functions. How can I achieve that?
If I understand your question correctly, this sounds like a job for functools.partial
:
def f(x1, x2):
return x1 + x2
from functools import partial
funcs = [partial(f, x2=i) for i in range(10)] # example use case