While I am using my partial function I am unable to do the following code
from functools import partial
def f(a, b, c, d):
return 100 * a + 50 *b + 25 * c + d
g = partial(f, b=2)
print g(2, 4, 5)
While I am using my partial function I am unable to do the following code
from functools import partial
def f(a, b, c, d):
return 100 * a + 50 *b + 25 * c + d
g = partial(f, b=2)
print g(2, 4, 5)
You can't make partial with positional arguments other than last.
If you need to make partial of b
, you need to pass c
and d
by name:
g = partial(f, b=2)
print(g(2, c=4, d=5))
Or use lambda
(or wrapper function) if you need to pass positional args
we can call g()
to check the function, then you get a info:
TypeError: f() missing 3 required positional arguments: 'a', 'c', and 'd'
Now, we can know that there is an argument b
,we can specify the arguments c
and d
:
g(2, c=4, d=5)
405