Created
November 10, 2020 08:34
-
-
Save PrudhviVajja/1db8627077d9102aaf18d61db860d792 to your computer and use it in GitHub Desktop.
SimpleDecorator
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 func_name_printer(func): | |
def wrapper(*args): | |
print("Function that started running is " + func.__name__) | |
func(*args) | |
return wrapper | |
def add(*args): | |
tot_sum = 0 | |
for arg in args: | |
tot_sum += arg | |
print("result = " + str(tot_sum)) | |
sample = func_name_printer(add) | |
# ex 1 | |
sample(1,2) | |
# Function that started running is add | |
# result = 3 | |
# ex 2 | |
sample(1,2,3) | |
# Function that started running is add | |
# result = 6 | |
# ex 3 | |
sample(1,2,3,4) | |
# Function that started running is add | |
# result = 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment