mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 08:21:12 -04:00
Add a useful way to understand python decorator
This commit is contained in:
parent
3cc8c1d5c0
commit
ac67b30284
1 changed files with 19 additions and 0 deletions
19
source_code/learning/decorator.py
Normal file
19
source_code/learning/decorator.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/python
|
||||
#
|
||||
# An example of Python Decorator
|
||||
#
|
||||
|
||||
def pretty_sumab(func):
|
||||
def inner(a,b):
|
||||
print(str(a) + " + " + str(b) + " is ", end="")
|
||||
return func(a,b)
|
||||
|
||||
return inner
|
||||
|
||||
@pretty_sumab
|
||||
def sumab(a,b):
|
||||
summed = a + b
|
||||
print(summed)
|
||||
|
||||
if __name__ == "__main__":
|
||||
sumab(5,3)
|
Loading…
Add table
Add a link
Reference in a new issue