google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Lambda Function in Python

Lambda Function in Python

0

 


A lambda function is an unnamed function with a small size. As we already know that the def keyword is used to define a normal function in Python. Similarly, the lambda keyword is used to define an anonymous function in Python.

A lambda function can take any number of parameters, but only one expression can be used.

Syntax

lambda arguments : expression

 

  1. This function accepts any number of inputs but only evaluates and returns one expression.
  2. Lambda functions can be used whenever function objects are necessary.
  3. It's important to remember that lambda functions are syntactically limited to a single expression.
  4. Apart from other forms of expressions in functions, it has a variety of applications in certain domains of programming.

Example:

 

#Write a Program Lambda Function use only one Argument with one Expression

 

a = lambda x : x + 10

print(‘The Value of Expression with one Argument is =’a(5))

 

Output:

The Value of Expression with one Argument is =15

 

Example:

 

#Write a Program Lambda Function use Two Argument with one Expression

 

a = lambda x, y : x * y

print(‘The Value of Expression with two Argument is =’, a(5, 6))

 

Output:

The Value of Expression with two Argument is =30

 

Note: we can use more than one argument list separated by comma (,).

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top