Predict the partial Output
Beginner · Predict the output · from Python functools: lru_cache, partial, reduce, singledispatch
From the lesson: Python functools: lru_cache, partial, reduce, singledispatch
Imagine your functions could remember past answers, come pre-loaded with some arguments, or automatically handle different data types. That's what the functools module gives you: power-ups for your functions.
Read the lessonWhat does this code print? Think about which argument gets pre-filled.
from functools import partial
def add(a, b, c):
return a + b + c
add_10 = partial(add, 10)
result = add_10(20, 30)
print(result)from functools import partial
def add(a, b, c):
return a + b + c
add_10 = partial(add, 10)
result = add_10(20, 30)
print(result)
More functools exercises
- Cache a Factorial FunctionIntermediate
- Create a Percentage Calculator with partialIntermediate
- Reduce a List to Find the MaximumIntermediate
- Build a String with reduceAdvanced
- Create a singledispatch FormatterAdvanced
- Fix the Caching BugAdvanced
All Python exercises · 50 practice problems · Standard Library Essentials quiz