Partial Function (functools.partial)

say it: “PAR-shul FUNGK-shun” /ˈpɑrʃəl ˈfʌŋkʃən/ or “FUNK-toolz dot PAR-shul” /ˈfʌŋkˌtulz dɑt ˈpɑrʃəl/

A copy of a function with some arguments already filled in.

What is a partial function?

A partial function is a copy of a function with some arguments already filled in, made with functools.partial.

from functools import partial

def price_with_tax(price, rate):
    return round(price * (1 + rate), 2)

colorado_price = partial(price_with_tax, rate=0.029)
print(colorado_price(100))  # 102.9

Level: Freelancer · More Python terms at this level

Updated