========================================================
Anonymous Functions OR Lambda Functions
========================================================
=>Anonymous Functions which does not contain any name explicitly.
=>The Purpose of Anonymous Functions is that " To Perform Instant Operations".
=>Instant Operations are Operations those which we can perform at that point of
time only and no longer
interested to re-use in other part of the application".
=>To Develop / Define Anonymous Functions, we use a keyword lambda and hence
Anonymous
Functions are also called Lambda Functions.
=>Anonymous Functions contains Single Executable Statement only (But not Multiple
statements)
=>Anonymous Functions automatically / Implcitly returns the value(No Need to use
return statement).
----------------
Syntax:
----------------
varname=lambda params-list : Expression
Explanation:
-------------------
=>Varname represents an object of <class, 'function'> and we can Varname as
Function Call and Indirect
name of Anonymous Function
=>lambda is keyword used for defining Anonymous Functions.
=>params-list represents list formal parameter used for storing the values coming
from function call.
=>Expression represents Single Executable Statementa and it performs Instant
Operation and whose
result returns automatically / Implcitly(No Need to use return statement).
-----------------------------------------------------------------------------------
-------------------------------------------------------
Q) Define a function addition of two numbers
-----------------------------------------------------------------------------------
-------------------------------------------------------
By using Normal Function By using Anonymous Functions
------------------------------------------------
---------------------------------------------------------
def addop(a,b): sumop=lambda a,b: a+b
c=a+b
return c
#main program #main program
res=addop(10,20) res=sumop(10,20)
print(res) # 30 print("Result=",res)
-----------------------------------------------------------------------------------
-------------------------------------------------------