Created
September 4, 2020 03:48
-
-
Save ycui1/49d2cc1a65063244ec1bef4884ce4a1c to your computer and use it in GitHub Desktop.
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
>>> class Repeat: | |
... def __init__(self, n): | |
... self.n = n | |
... | |
... def __call__(self, func): | |
... def repeater(*args, **kwargs): | |
... for _ in range(self.n): | |
... func(*args, **kwargs) | |
... | |
... return repeater | |
... | |
... @Repeat(n=2) | |
... def morning_greet(person): | |
... print(f"Good Morning, {person}!") | |
... | |
... @Repeat(n=3) | |
... def afternoon_greet(person): | |
... print(f"Good Afternoon, {person}!") | |
... | |
... morning_greet("Jason") | |
... afternoon_greet("Kelly") | |
... | |
Good Morning, Jason! | |
Good Morning, Jason! | |
Good Afternoon, Kelly! | |
Good Afternoon, Kelly! | |
Good Afternoon, Kelly! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment