Last active
September 10, 2020 14:46
-
-
Save Jay-flow/0ce1b3e71de13238b2c99bbef033effd to your computer and use it in GitHub Desktop.
Decorator example code
This file contains hidden or 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 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