You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-5
Original file line number
Diff line number
Diff line change
@@ -3269,14 +3269,35 @@ For more details about errors and exceptions follow this [https://docs.python.or
3269
3269
<details>
3270
3270
<summary>What is Lambda? How is it used?</summary><br><b>
3271
3271
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.
3273
3273
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 =lambdaa: a +10
3284
+
print(x(10))
3285
+
```
3286
+
3287
+
* An addition function
3288
+
3289
+
```py
3290
+
addition =lambdax, y: x + y
3291
+
print(addition(10, 20))
3275
3292
```
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 =lambdax : x **2
3298
+
print(square(5))
3279
3299
```
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.
0 commit comments