higher-order function
In programming, a higher-order function is a function that either takes one or more functions as arguments or returns a function as its result. This powerful feature allows you to create more abstract and flexible code.
Higher-order functions are a cornerstone of functional programming, enabling you to use functions like map()
, filter()
, and lambda
function to manipulate data in a clean and expressive way.
You can often replace loops with higher-order functions for writing more concise and readable code. This can make your code more modular and maintainable.
Example
Here’s a quick example of using map()
, which is a higher-order function in Python:
>>> def square(base):
... return base**2
...
>>> list(map(square, [1, 2, 3, 4, 5]))
[1, 4, 9, 16, 25]
In this example, map()
takes the square()
function and applies it to each element in the provided list, resulting in a new list of square values.
Related Resources
Tutorial
Functional Programming in Python: When and How to Use It
In this tutorial, you'll learn about functional programming in Python. You'll see what functional programming is, how it's supported in Python, and how you can use it in your Python code.
For additional information on related topics, take a look at the following resources:
- Python's map(): Processing Iterables Without a Loop (Tutorial)
- Python's filter(): Extract Values From Iterables (Tutorial)
- Python's reduce(): From Functional to Pythonic Style (Tutorial)
- Defining Your Own Python Function (Tutorial)
- The Python return Statement: Usage and Best Practices (Tutorial)
- Functional Programming in Python: When and How to Use It (Quiz)
- Python's map() Function: Transforming Iterables (Course)
- Filtering Iterables With Python (Course)
- Defining and Calling Python Functions (Course)
- Defining Your Own Python Function (Quiz)
- Using the Python return Statement Effectively (Course)
- The Python return Statement (Quiz)
By Leodanis Pozo Ramos • Updated April 16, 2025