January 2015
Intermediate to advanced
360 pages
8h 50m
English
The
partial() function leads to something called partial application. A partially applied function is a new function built from an old function and a subset of the required arguments. It is closely related to the concept of currying. Much of the theoretical background is not relevant here, since currying doesn't apply to the way Python functions are implemented. The concept, however, can lead us to some handy simplifications.
We can look at trivial examples as follows:
>>> exp2= partial(pow, 2) >>> exp2(12) 4096 >>> exp2(17)-1 131071
We've created a function, exp2(y), which is the pow(2,y) function. The partial() function bounds the first positional parameter to the pow() function. When we evaluate the ...
Read now
Unlock full access