From the course: Functional Programming with Python

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Passing functions as arguments

Passing functions as arguments - Python Tutorial

From the course: Functional Programming with Python

Passing functions as arguments

- [Instructor] Now that we've seen a few ways that we can treat functions in the same way as other types, such as numbers or strings, the next step is to look at how we can pass functions as arguments to other functions. Up until now, you've probably been used to passing arguments into functions with the purpose of specifying what the data is that we're operating on. If we pass two numbers into a function called add, for example, we're specifying the two numbers that we want to add together. But what if, instead of passing arguments into our function to specify what our data is, we could pass in arguments to specify what was done to that data? And this is one of the important things that first-class functions let us do. So to illustrate this point, let's take a look at these two very simple functions, add and subtract, defined here. Each of these functions takes two arguments, and then either adds or subtracts the two…

Contents