Skip to content

Commit ac67b30

Browse files
author
bt3
committed
Add a useful way to understand python decorator
1 parent 3cc8c1d commit ac67b30

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

source_code/learning/decorator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/python
2+
#
3+
# An example of Python Decorator
4+
#
5+
6+
def pretty_sumab(func):
7+
def inner(a,b):
8+
print(str(a) + " + " + str(b) + " is ", end="")
9+
return func(a,b)
10+
11+
return inner
12+
13+
@pretty_sumab
14+
def sumab(a,b):
15+
summed = a + b
16+
print(summed)
17+
18+
if __name__ == "__main__":
19+
sumab(5,3)

0 commit comments

Comments
 (0)