Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Using Functional Programming in Python (Summary)

Functional programming is a programming paradigm in which the primary method of computation is the evaluation of pure functions. Even though Python isn’t primarily a functional language, you can still write Python following functional programming principles.

To do this, it’s a good idea to be familiar with lambda, map(), filter(), and reduce(). They can help you write concise, high-level, parallelizable code. You may also see these functions used in code that others have written, so it’s good to understand how they work.

In this video course, you learned:

  • What functional programming is
  • How functions in Python are first-class citizens, and how that makes them suitable for functional programming
  • How to define a simple anonymous function with lambda
  • How to implement functional code with map(), filter(), and reduce()

Resources linked in this lesson:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

00:00 In the previous lesson, I showed you the last of the three most common functional programming utilities: reduce(). This lesson summarizes the course and points you at other content.

00:11 Programming languages come in three high-level styles: procedural, where the code is more or less ordered; object-oriented, where data and operations on that data is grouped together; and functional programming, where you chain function calls together to get results.

00:26 To use a functional programming style, the language needs to support the ability to treat a function as a piece of data. So not just being able to invoke it, but being able to pass around references to it as well.

00:37 Everything in Python is an object, even the functions, which is how it fulfills the function as data requirement I just mentioned.

00:46 A Python lambda is an anonymous inline function, which often gets used when you just need a one-liner. Python lambdas are restricted to being a single statement, which limits what they can be used for, but also tends to allow the compiler to optimize them.

01:01 This course was mostly on the three most common utilities used when doing functional programming: map(), which you use to invoke a callable on every item in an iterable; filter(), which you use to remove items from an iterable that don’t meet some criteria specified by the truthy return value of a callable; and reduce(), which composes a result with the next item in an iterable to produce a new result.

01:27 There’s always more content at Real Python. This very in-depth course and tutorial cover lambdas in great detail if you want to dig in there some more. There are tutorials on each of the map(), filter() and reduce() functions.

01:42 They don’t really cover anything that you haven’t seen in this course already, but they do have some more examples if you’d like to see other uses. Each of them has a corresponding video course as well, which is linked in the top of the tutorial if you prefer to get your content that way.

01:58 Finally, if you want to learn more about concurrency and the kind of composed patterns I was talking about before, this course will teach you all about I/O-bound and CPU-bound concurrency.

02:09 That’s all I’ve got for now. I hope you learned something useful. Thanks for your attention.

Become a Member to join the conversation.