Skip to content

Commit 7b7e78e

Browse files
authored
update answer under Python/lambda
1 parent 298e62f commit 7b7e78e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

Diff for: README.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -3269,14 +3269,35 @@ For more details about errors and exceptions follow this [https://docs.python.or
32693269
<details>
32703270
<summary>What is Lambda? How is it used?</summary><br><b>
32713271

3272-
Lambda is an anonymous function is known as a lambda function. This function can have any number of parameters but, can have just one statement.
3272+
A <code>lambda</code> expression is an 'anonymous' function, the differnce between a normal defined function using the keyword `def`` is the syntax and ussage.
32733273

3274-
Example:
3274+
The syntax is:
3275+
3276+
```lambda[parameters]: [expresion]```
3277+
3278+
**Examples:**
3279+
3280+
* A lambda function add 10 with any argument passed.
3281+
3282+
```py
3283+
x = lambda a: a + 10
3284+
print(x(10))
3285+
```
3286+
3287+
* An addition function
3288+
3289+
```py
3290+
addition = lambda x, y: x + y
3291+
print(addition(10, 20))
32753292
```
3276-
1 a = lambda x,y : x+y
3277-
2 print(a(5, 6))
3278-
Output: 11
3293+
3294+
* Squaring function
3295+
3296+
```py
3297+
square = lambda x : x ** 2
3298+
print(square(5))
32793299
```
3300+
Generally it is considered a bad practice under PEP 8 to asign a lambda expresion, they are meant to be used as parameters and inside of other defined functions.
32803301

32813302
</b></details>
32823303

0 commit comments

Comments
 (0)