8000 Adds First Class Functions · georgecms/complete-python-course@01715f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01715f7

Browse files
Adds First Class Functions
1 parent e5cf30f commit 01715f7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

course_contents/2_intro_to_python/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,24 @@ result = (lambda x, y: x + y)(15, 3)
199199
```
200200

201201
Read more about lambda expressions and first-class functions [here](https://www.teclado.com/30-days-of-python/python-30-day-16-lambda-expressions).
202+
203+
# First Class Functions
204+
205+
- Functions in Python are "first class citizens".
206+
- This means they are objects that can be stored in data structures and passed as arguments, and stored in variables.
207+
208+
Example:
209+
210+
```python
211+
# Each of avg, sum, max are functions, and since they are First Class Citizens, they can be stored in this dictionary.
212+
operations = {
213+
"average": avg,
214+
"total": sum,
215+
"top": max
216+
}
217+
218+
# We can also use associations to get a function from the dictionary.
219+
selection = "average"
220+
operation = operations[selection]
221+
operation() # This is acts the same as simply calling avg()
222+
```

0 commit comments

Comments
 (0)
0