what is the usage of python lambda functions

Lambda is a keyword used to create an functions without a name or in simple lambda is used to create an anonymous functions,lambda function has n number of argument with a single expression which is processed and returned the result.we know normally a function is defined in python using def statement followed by function name and argument after evaluating it should return the result to get the result value when function is called but lambda has no name and return statement

Syntax Lambda functon

lambda arguments : expression


Tenpercentage= lambda x :x * 10/100  

#"x" is an argument and "x * 10/100" is an expression which got evaluated and returned.   




python lambda functions

See above code in Normal functions syntax

def Tenpercentage(n):
  return n * 10/100


common usage of python lambda functions

Lambda function perform well if we use lambda functions inside another function see example

See example

def currency_convert(currencyvalue):  
    return lambda x:x*currencyvalue;

Israelicurrency=currency_convert(3.48);  #find dollar to Israeli New Shekel



indiancurrency=currency_convert(71.57);  #Find dollar to INR



python lambda functions inside anothor function

Leave a Reply

Your email address will not be published. Required fields are marked *