Python: functools.partial


I’m studying python, and I try to write daily technical memo for myself.


I learned functools.partial today.


import functools
import math

#paramter PI and radius

circle_squre = lambda pi, r: pi * r * r

calc_circle1 = functools.partial(circle_squre, 3)
calc_circle2 = functools.partial(circle_squre, math.pi)

R = 5
print calc_circle1(R)
print calc_circle2(R)

Leave a Reply

Your email address will not be published. Required fields are marked *