163. Using functools.partial for Function Customization
from functools import partial
# Function that adds two numbers
def add(a, b):
return a + b
# Freeze the value of 'a' to 10
add_10 = partial(add, 10)
# Call the partially frozen function
result = add_10(5) # This will add 10 + 5
print(f"Result: {result}")from functools import partial
# Function that adds three numbers
def add_three(a, b, c):
return a + b + c
# Freeze 'a' to 5 and 'b' to 10
add_5_and_10 = partial(add_three, 5, 10)
# Call the partially frozen function
result = add_5_and_10(15) # This will add 5 + 10 + 15
print(f"Result: {result}")Last updated