Created
June 17, 2024 12:40
-
-
Save theSamyak/d2a3999e45b473d3adafa11e69407b3f to your computer and use it in GitHub Desktop.
Example: Creating Multiplier Functions with Lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_multiplier(factor): | |
return lambda x: x * factor | |
# 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