Skip to content

Instantly share code, notes, and snippets.

@Jay-flow
Last active September 10, 2020 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jay-flow/0ce1b3e71de13238b2c99bbef033effd to your computer and use it in GitHub Desktop.
Save Jay-flow/0ce1b3e71de13238b2c99bbef033effd to your computer and use it in GitHub Desktop.
Decorator example code
def decorator_function(original_function):
def add_espresso():
print("Add espresso")
return original_function()
return add_espresso
def add_water():
print("Add Water")
def add_milk():
print("Add Milk")
americano = decorator_function(add_water)
latte = decorator_function(add_milk)
print("# Americano Recipe")
americano()
print("# Latte Recipe")
latte()
# The code above is output as follows.
# # Americano Recipe
# Add espresso
# Add Water
# # Latte Recipe
# Add espresso
# Add Milk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment