Skip to content

Commit c018794

Browse files
author
SanjayPradeeo
committed
Further more explanation
Decorator example, writing a function inside a method, and returning it.
1 parent ade223f commit c018794

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Decorators/WhatIsDecorators.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,37 @@ def first(msg):
3030

3131
# Here's the example.
3232

33+
def add(firstInput, secondInput):
34+
return firstInput + secondInput
35+
36+
def sub(firstInput, secondInput):
37+
return firstInput - secondInput
38+
39+
def operation(func, firstInput, secondInput):
40+
result = func(firstInput, secondInput)
41+
return result
42+
43+
# Here you go ..
44+
45+
output = operation(add, 10, 10) # assinging the result to a variable, because operation method is going to return a value
46+
47+
print (output) #output : 20
48+
49+
# Further more, a sample example..
50+
51+
def is_called():
52+
def is_returned():
53+
print("Hello")
54+
return is_returned
55+
56+
new = is_called()
57+
print (new())
58+
59+
#Here's the Output below ..
60+
# "Hello"
61+
# None - basically is_called function returns is_returned method (which in turn prints "hello") so this throws None.
62+
63+
64+
65+
66+

0 commit comments

Comments
 (0)