0% found this document useful (0 votes)
10 views1 page

Anonymous Functions or Lambda Functions

Anonymous functions, also known as lambda functions, are unnamed functions used for performing instant operations that are not intended for reuse. They are defined using the 'lambda' keyword and consist of a single executable statement that implicitly returns a value. The document provides a syntax example and compares a normal function with an anonymous function for adding two numbers.

Uploaded by

bb7608758
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Anonymous Functions or Lambda Functions

Anonymous functions, also known as lambda functions, are unnamed functions used for performing instant operations that are not intended for reuse. They are defined using the 'lambda' keyword and consist of a single executable statement that implicitly returns a value. The document provides a syntax example and compares a normal function with an anonymous function for adding two numbers.

Uploaded by

bb7608758
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

========================================================

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)
-----------------------------------------------------------------------------------
-------------------------------------------------------

You might also like