Skip to content

Instantly share code, notes, and snippets.

@theSamyak
Last active May 25, 2024 12:14
Show Gist options
  • Save theSamyak/8b2c4a44517c9baac24dd4123e49d660 to your computer and use it in GitHub Desktop.
Save theSamyak/8b2c4a44517c9baac24dd4123e49d660 to your computer and use it in GitHub Desktop.
[FCC First class and Closures Blog] Returning Functions from Other Functions
def create_multiplier(factor):
"""Returns a function that multiplies its input by the given factor."""
def multiplier(x):
return x * factor
return multiplier
# Create specific multiplier functions
double = create_multiplier(2)
triple = create_multiplier(3)
# Use the created functions
print(double(5)) # Output: 10
print(triple(5)) # Output: 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment