Lambda function in python | Anonymous Function | Hindi | Lambda tutorial

Publié le: 28 août 2024
sur la chaîne: CodeBuster
1,129
39

Lambda function tutorial in hindi. It is also known as anonymous function.
It is a part of advanced python concept which is mostly asked in interviews.

Lambda functions, also known as anonymous functions, are particularly useful in situations where you need a function for a short period and don't want to formally define it with the `def` keyword. This is especially helpful when using functions like `map`, `filter`, and `reduce` where you need to pass a function as an argument.

Let's illustrate this with the example from the source. Imagine you want to calculate the square of a number. You could define a regular function:

```python
def square(a):
return a * a
```

Then you could call this function to get the square of a number:

```python
result = square(5)
print(result) # Output: 25
```

This works well, but it involves several lines of code for a simple operation. With a lambda function, you can achieve the same result in a single line:

```python
square = lambda a: a * a
result = square(5)
print(result) # Output: 25
```

This lambda function takes an argument `a` and returns its square (`a * a`). This concise format is beneficial when you need a simple function for a one-time use within another function.

While the source mainly illustrates the concept with basic mathematical operations, the true power of lambda functions shines when used with functions like `map`, `filter`, and `reduce`. These functions often require a function as an argument to apply to a sequence of elements. Lambda functions, due to their conciseness, fit perfectly in such scenarios.

Although the source doesn't provide specific examples of using lambda functions with `map`, `filter`, and `reduce`, it does mention that these are important concepts where lambda functions are widely used. It suggests that these topics will be covered in a future video.

#lambdaexpression
#pythoninterviewquestionsandanswers


Sur cette page du site, vous pouvez voir la vidéo en ligne Lambda function in python | Anonymous Function | Hindi | Lambda tutorial durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur CodeBuster 28 août 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,129 fois et il a aimé 39 téléspectateurs. Bon visionnage!