From 7b7e78e2f72b3c67431d7de74426a7dd055df3d2 Mon Sep 17 00:00:00 2001 From: Sagor Sarker Date: Wed, 22 Jan 2020 14:43:32 +0600 Subject: [PATCH] update answer under Python/lambda --- README.md | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 92c0526..e75ea66 100644 --- a/README.md +++ b/README.md @@ -3269,15 +3269,36 @@ For more details about errors and exceptions follow this [https://docs.python.or
What is Lambda? How is it used?
-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. +A lambda expression is an 'anonymous' function, the differnce between a normal defined function using the keyword `def`` is the syntax and ussage. -Example: +The syntax is: + +```lambda[parameters]: [expresion]``` + +**Examples:** + +* A lambda function add 10 with any argument passed. + +```py +x = lambda a: a + 10 +print(x(10)) ``` -1 a = lambda x,y : x+y -2 print(a(5, 6)) -Output: 11 + +* An addition function + +```py +addition = lambda x, y: x + y +print(addition(10, 20)) ``` +* Squaring function + +```py +square = lambda x : x ** 2 +print(square(5)) +``` +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. +
#### Properties