Skip to content

Commit d3b54d3

Browse files
authored
Update III Decorators.py
1 parent a811c16 commit d3b54d3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Writing Functions in Python/III Decorators.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,30 @@ def multiply(a,b):
341341
342342
# 20
343343
**********************************************************************************************************************************************************"""
344+
## Using decorator syntax
345+
346+
"""You have written a decorator called print_args that prints out all of the arguments and their values any time a function that it is decorating gets called."""
347+
def my_function(a, b, c):
348+
print(a + b + c)
349+
350+
# Decorate my_function() with the print_args() decorator by replacing my_fuction variable
351+
my_function = print_args(my_function)
352+
353+
my_function(1, 2, 3)
354+
355+
# my_function was called with a=1, b=2, c=3
356+
# 6
357+
358+
## Using decorator syntax 2
359+
360+
# Decorate my_function() with the print_args() decorator above
361+
@print_args
362+
def my_function(a, b, c):
363+
print(a + b + c)
364+
365+
my_function(1, 2, 3)
366+
367+
# my_function was called with a=1, b=2, c=3
368+
# 6
369+
#`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
370+
##

0 commit comments

Comments
 (0)