From the course: Functional Programming with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Functions as data, part 2

Functions as data, part 2 - Python Tutorial

From the course: Functional Programming with Python

Start my 1-month free trial

Functions as data, part 2

- [Instructor] In this video, we're going to look at another example of an interesting thing that can be done with first class functions. Just as we can create a list of other data types like numbers or strings, because functions in Python are first class, we can also create a list of functions. Now, you might be wondering why we'd want to do something like that. Well, let's say that we have a few different functions that we've created, all of which take an argument to make some sort of change to that argument, like doubling it or subtracting from it, and so on. And now let's say that we want to get the result of a number when all these functions are applied to it. The mechanical way of doing this, would be something like this. If we have our number, my number equals three. Then we'd say my number equals double my number, and this would be doubling it. And then if we want to apply minus one to it, we'd say my number…

Contents