Loading video player…

Using Functional Programming in Python (Overview)

Functional programming is a programming paradigm in which the primary method of computation is the evaluation of functions. But how does Python support functional programming?

In this video course, you’ll learn:

  • What the functional programming paradigm entails
  • What it means to say that functions are first-class citizens in Python
  • How to define anonymous functions with the lambda keyword
  • How to implement functional code using map(), filter(), and reduce()
Download

Course Slides (.pdf)

881.5 KB
Download

Sample Code (.zip)

3.6 KB

00:00 Welcome to Using Functional Programming in Python. My name is Christopher, and I will be your guide.

00:07 This course is all about functional programming. That’s an approach to coding that primarily focuses on the combinations of functions. Python supports functional programming since its functions are objects, meaning they can be passed as references, returned from other functions, and have values assigned to them.

00:25 This can seem a little odd if you’re more accustomed to the procedural programming world, and there are other languages that focus solely on this approach, but Python supports it, and for certain classes of problems, it can be the right way to go about doing things.

00:39 There are three functions that come with Python that are commonly used with a functional programming approach. They are map(), which applies a function to each item in an iterable, filter(), which creates a subset of an iterable based on filtering criteria, and reduce(), which combines the items in an iterable through composition, for example, accumulating a sum.

01:02 This course introduces you to the functional programming approach and concentrates on these three functions in the Python language.

01:10 The code in this course was tested using Python 3.14, but that really doesn’t matter. The concepts here have been around in Python for a very long time. The reduce() function got moved from being a built-in to the functools module in Python 3, but as long as you know where to find it, you can do almost everything that I’m going to show you here with older versions of the interpreter.

01:32 Functional programming is a coding approach based on composing functions together to achieve your results. Some languages work exclusively this way, and others, like Python, allow it if you feel like it.

01:44 Python supports a functional programming approach because functions themselves are objects, which means you can assign values to them. Note, I mean actually assigning properties to the function itself, not just defining a variable within them.

01:58 It also means you can pass a function as a reference, treating it like data, not just invoking it, and ultimately, that same concept extends to the fact that you can return a function reference from another function or method.

02:10 Python’s built-in library includes the map() and filter() functions, and the functools module contains a lot of other tools that support a functional programming approach.

02:21 In the next lesson, I’ll kick things off by explaining the different programming approaches and just what it means to be functional.

Become a Member to join the conversation.