Home >> Python Tutorial >> Lambda Function
Edit Template
Edit Template

Lambda Function in Hindi

What is Lambda Function

Lambda Function एक anonymous (nameless) function होता है जिसे “lambda” keyword का use करके बनाया जाता है। जब हमे कोई छोटा function (जो एक ही line में define हो जाए) बनाना होता है तो हम lambda function बनाते है।

SYNTAX

lambda arguments : expression

🐍
Example 1.py
Copy to clipboard
square = lambda x: x * x
print(square(5))
 # Output: 25

Nested Lambda Function

जब एक lambda function के अंदर किसी दूसरे lambda function को use करते है या फिर वो lambda function किसी दूसरे function को return करता है तो उसे nested lambda function कहा जाता है।

🐍
Example 2.py
Copy to clipboard
nested = lambda x: (lambda y: x + y)
add5 = nested(5)   # ab ye ek lambda return karega
print(add5(10))    # 5 + 10

# Output: 15

Lambda Function with if-else

Lambda function में एक line का if-else condition यानि की ternary operator को use किया जा सकता है।

🐍
Example 3.py
Copy to clipboard
check = lambda x: "Even" if x % 2 == 0 else "Odd"

print(check(10))
print(check(7))

'''Output: Even
           Odd

Lambda Function with List Comprehension

Lambda function को हम list comprehension (यानि list body में lambda function define करना) में use कर सकते है। इसका mostly use list transformation में किया जाता है, for example किसी number list के सारे items का square list बनाना हो तो हम इस technique से बना सकते है।

🐍
Example 4.py
Copy to clipboard
nums = [1, 2, 3, 4, 5]
squares = [(lambda x: x*x)(n) for n in nums]

print(squares)

# Output: [1, 4, 9, 16, 25]

IIFE

IIFE (Immediately Invoked Function Expression) एक ऐसा function होता है जो बनते ही execute हो जाता है, but python में हम normal function (जो “def” keyword के use से बनते है) से IIFE function नहीं बना सकते, क्योंकि ऐसा करने पर syntax error आ जाएगा, इसीलिए हम lambda function का use करके IIFE function को create करते है।

🐍
Example 5.py
Copy to clipboard
result = (lambda x, y: x + y)(10, 20)
print(result)

# Output: 30

उम्मीद करते है कि आपको Lanbda Function अच्छे समझ मे आ गया होगा। अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Fundamentals
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
Dunder Methods

Table of Contents All Chapters 1. Dunder Methods 2. Commonly Used Dunder Methods   Python Tutorial Python Introduction Identation &...

Encapsulation

Table of Contents All Chapters 1. Encapsulation 2. Access Modifiers      2.1. Public Members      2.2. Protected Members...

Lambda Function

Table of Contents All Chapters 1. Lambda Function 2. Nestesd Lambda Function 3. Lambda Function with if-else 4. Lanbda with...

Nested Function

Table of Contents All Chapters 1. Nested Function 2. Return Function from Function 3. Higher Order Function 4. Function Recursion...

Context Manager

Table of Contents All Chapters 1. Context Manager 2. with Statement      2.1. __enter__() Method      2.2. __exit__()...

File Pointer

Table of Contents All Chapters 1. File Pointer 2. File Pointer Methods      2.1. tell() Method      2.2....

File Handling

Table of Contents All Chapters 1. File Handling 2. Types of File 3. open() and close() Methods 4. File Modes...

Edit Template
Scroll to Top