mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
Add a useful way to understand python decorator
This commit is contained in:
parent
3cc8c1d5c0
commit
ac67b30284
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…
x
Reference in New Issue
Block a user