April 27th, 2013, 08:13 PM
I was going through a online interactive python tutorial and I came to the section on partial functions, but I don't really understand how it works. The function below looks simple, but the answer I come up with a calculator is 66 and not 60 which is the correct answer so I thought I would ask if someone could go through this code and tell me how it works.
from functools import partial
return u*4 + v*3 + w*2 + x
p = partial(func,5,6,7)
April 27th, 2013, 09:06 PM
Of course we don't know which calculator buttons you pressed. Given that mp is the matrix product, 60 is the correct answer. (www.jsoftware.com)
Maybe the partial is clearer with keyword arguments
5 6 7 8 mp 4 3 2 1
>>> p = partial(func,u=5,v=6,w=7)
>>> p(w=8) # deliberate error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: func() takes exactly 4 arguments (3 given)
Last edited by b49P23TIvg; April 27th, 2013 at 09:11 PM.
[/code] are essential for python code and Makefiles!