partial functions in Python

PHOTO EMBED

Tue Jun 18 2024 02:53:02 GMT+0000 (Coordinated Universal Time)

Saved by @pynerds #python

import functools

def power(a, b):
    return a ** b

square = functools.partial(power, b = 2)
cube = functools.partial(power, b = 3)

print(square(5))
print(cube(5))
content_copyCOPY

https://www.pynerds.com/partial-functions-in-python/