Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lambda Functions | Functions
Introduction to Python

Lambda FunctionsLambda Functions

All the functions we've created up until now are stored in memory after the code runs for the first time. However, there are times when you might not want to create a standalone function, especially for straightforward tasks. In these situations, you can use Python's lambda function, which is essentially an anonymous function. Here's the syntax:

As an illustration, let's revisit our initial function. We can refactor it using a lambda function to return the squared sum of two numbers:

Note

As you might infer, not all functions we've discussed can be converted into lambda functions. Typically, lambda functions are best suited for concise operations that fit within a single line.

Everything was clear?

Section 6. Chapter 11
course content

Course Content

Introduction to Python

Lambda FunctionsLambda Functions

All the functions we've created up until now are stored in memory after the code runs for the first time. However, there are times when you might not want to create a standalone function, especially for straightforward tasks. In these situations, you can use Python's lambda function, which is essentially an anonymous function. Here's the syntax:

As an illustration, let's revisit our initial function. We can refactor it using a lambda function to return the squared sum of two numbers:

Note

As you might infer, not all functions we've discussed can be converted into lambda functions. Typically, lambda functions are best suited for concise operations that fit within a single line.

Everything was clear?

Section 6. Chapter 11
some-alt