Editor

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 lesson

What 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

All Python exercises · 50 practice problems · Standard Library Essentials quiz