![]() |
VOOZH | about |
The lambda function is an anonymous function. It can have any number of arguments but it can only have one expression.
Syntax lambda arguments : expression
In this article, we will learn how to find the smaller value between two elements using the Lambda function.
Example:
Input : 2 5 Output : 2 Input : 7 5 Output : 5
Output:
5
Explanation: The a,b are passed to the lambda function and min() method is used as an expression to return the minimum element.
Output:
5
Explanation: a, b are the arguments and ternary operator is used for comparing two elements
Output:
5
Explanation:
Two lambda functions will be stored in a tuple such that 1st element is b and 2nd element will be b. if [a<b] is true it return 1 and element with index 1 will print else if [a<b] is false it return 0, so element with index 0 will print.