Lambda Functions in Python

A lambda function in Python is a small and anonymous function. It has no name, and it's used for simple operations that are done in one line.

It is useful when we want to write short functions without using the def keyword.

Syntax:

lambda arguments : expression

Note: The result of the expression is automatically returned.

Example 1: Lambda to add two numbers

add = lambda a, b: a + b
print("Sum is:", add(5, 3))

Output:

Sum is: 8

Explanation:

  • lambda a, b: a + b defines an anonymous function.
  • It takes two inputs and returns their sum.
  • The function is assigned to add and called using add(5, 3).

Example 2: Lambda with no variable assignment (used directly)

print((lambda x: x * x)(6))

Output:

36

Explanation:

  • The lambda function is created and used directly.
  • It takes input 6 and returns 6 × 6 = 36.

Where is Lambda used?

  • Inside map(), filter(), or reduce() functions
  • When a small function is needed temporarily
  • To reduce lines of code

Summary Table:

Term Description Example
lambda Creates an anonymous function lambda a, b: a + b
Used for Short, one-line functions Inside map(), filter()

Key Points to Remember:

  • Lambda functions are also called anonymous functions.
  • They are used for short operations written in a single line.
  • They do not need the return keyword explicitly.
  • Syntax: lambda arguments : expression

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar