---
title: "What are lambda functions in Python and how are they used?"  
description: "What are lambda functions in Python and how are they used?"  
author: "Steilla Mitchel"  
published: 2023-07-04  
updated: 2023-07-05  
canonical: https://www.mindstick.com/forum/158957/what-are-lambda-functions-in-python-and-how-are-they-used  
category: "python"  
tags: ["python", "functional programming"]  
reading_time: 2 minutes  

---

# What are lambda functions in Python and how are they used?

What are [lambda](https://www.mindstick.com/blog/181/lambda-expression-in-c-sharp) [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) in [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python) and how are they used?

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that.

## What are lambda functions?

In Python, lambda functions are anonymous functions. This means that they do not have a name, and they are defined using the `lambda` keyword. Lambda functions are often used as arguments to other functions, such as the `map()` and `filter()` functions.

## How are lambda functions used?

Lambda functions can be used in a variety of ways. Here are a few examples:

- **As arguments to other functions:** Lambda functions can be used as arguments to other functions, such as the `map()` and `filter()` functions. For example, the following code will use a lambda function to double the elements in a list:

Python

```plaintext
list1 = [1, 2, 3, 4, 5]
doubled_list = map(lambda x: x * 2, list1)
print(doubled_list)
```

The output of the code is:

Code snippet

```plaintext
[2, 4, 6, 8, 10]
```

- **As inline functions:** Lambda functions can be used as inline functions. This means that they can be defined and used in a single line of code. For example, the following code will define a lambda function that squares the elements in a list:

Python

```plaintext
square_list = list(map(lambda x: x ** 2, list1))
print(square_list)
```

The output of the code is:

Code snippet

```plaintext
[1, 4, 9, 16, 25]
```

- **As generators:** Lambda functions can be used as generators. This means that they can be used to generate a sequence of values. For example, the following code will define a lambda function that generates a sequence of even numbers:

Python

```plaintext
even_numbers = (x for x in range(10) if x % 2 == 0)
for number in even_numbers:
  print(number)
```

The output of the code is:

Code snippet

```plaintext
0
2
4
6
8
```


---

Original Source: https://www.mindstick.com/forum/158957/what-are-lambda-functions-in-python-and-how-are-they-used

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
