Unit: Unit 6: Functions • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Create function factories using nested functions and closures
def make_multiplier(factor):
# Inner function captures and remembers 'factor' from enclosing scope
def multiplier(number):
return number * factor
return multiplier
# Generate specialized multiplier functions
double = make_multiplier(2)
triple = make_multiplier(3)
print("Double 15:", double(15))
print("Triple 15:", triple(15))
print("Double 7:", double(7))