Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5820795

Browse files
Create 05_Higher_Order_Functions.MD
1 parent d457a2b commit 5820795

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎Lecture_17/05_Higher_Order_Functions.MD

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# **Higher Order Functions**
2+
3+
A function that either:
4+
* Accepts a function as an argument OR
5+
* Returns a function
6+
7+
In python functions are treated as an object.
8+
9+
**Example 1:**
10+
11+
```py
12+
def loud(text):
13+
return text.upper()
14+
def quiet(text):
15+
return text.lower()
16+
def hello(text):
17+
text = func("Hello")
18+
print(text)
19+
hello(loud)
20+
hello(quiet)
21+
```
22+
23+
**Example 2:**
24+
```py
25+
def divisor(x):
26+
def dividend(y):
27+
return y/x;
28+
divide = divisor(2)
29+
print(divide(10)) # 5.0
30+
31+
32+
"""
33+
10/2 = 5
34+
35+
10 = dividend
36+
2 = divisor
37+
5 = quotient
38+
"""
39+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /