Seedha content par jao
🤖 Python Hindi Bot
Namaste! Main Python Hindi Bot hoon 🐍
Python ya AI se related kuch bhi type karke pucho, ya neeche se quick sawaal chuno.
WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
⇧
Python Hindi Logo
Python in Hindi | Programming Education
Python programming tutorial in Hindi banner Python code learning illustration Hindi Python student coding illustration Python data code pattern background

Python Tutorial in HindiiLearn Python Programming for Free

Learn Python from Beginner to Advanced in simple Hindi.

print("Namaste Python!")
# Variable banana
naam = "Ankit"
umar = 25
 
for i in range(3):
  print("Sikho!")
 
# Output:
Sikho! Sikho! Sikho!

Why Students Learn Here

📚

Structured Tutorials

Beginner se Advanced tak step-by-step organized lessons.

💻

Practical Code

Real examples aur hands-on code jo actually samajh aaye.

🧠

Python + AI Path

Ek clear roadmap jo Python se AI tak le jaata hai.

🚀

Projects & Career

Portfolio-ready projects aur interview preparation.

Ye Kaise Kaam Karta Hai

Hindi mein Python, AI aur Data Skills seekhne ka sabse simple tareeka.

📘

Seekhein

Beginner se Advanced tak, best curated tutorials aur guides Hindi mein.

💻

Practice Karein

Real code examples aur mini-projects ke through hands-on practice karein.

💬

Judein

WhatsApp community se judkar apne doubts clear karein, akele nahi seekhenge.

Python to AI Learning Roadmap

Step-by-step learning path from Python basics to AI, Data Science and career-ready projects.

1
🐍

Python Basics

Introduction, Variables, Data Types, Operators, Input & Output, Conditions, Loops, Functions

Start Python →
2
💻

Python Intermediate

Lists, Tuples, Sets, Dictionaries, Strings, Functions, Modules, File Handling, Exception Handling

Continue Python →
3
⚙️

Advanced Python

OOP, Iterators, Generators, Decorators, Regular Expressions, APIs, Automation, Virtual Environments

Learn Advanced Python →
4
🗄️

SQL & Databases

SQL Basics, MySQL, SELECT, INSERT, UPDATE, DELETE, JOIN, GROUP BY, Database Projects

Learn SQL →
5
📊

Data Analytics

NumPy, Pandas, Data Cleaning, Data Visualization, Matplotlib, Exploratory Data Analysis

Learn Data Analytics →
6
🤖

Machine Learning

ML Basics, Supervised & Unsupervised Learning, Regression, Classification, Model Evaluation, Scikit-learn

Learn Machine Learning →
7
🧠

Artificial Intelligence

AI Fundamentals, Generative AI, AI Tools, Prompt Engineering, LLM Concepts, AI Automation

Explore AI →
8
🚀

Projects & Career

Python Projects, AI Projects, Data Projects, Portfolio, GitHub, Interview Preparation, Career Roadmap

Build Your Career →

Lambda Function in Python | Lambda Function क्या है? | Python Hindi

Python Lambda Function

Python Lambda Function

Python में normal function बनाने के लिए हम def keyword इस्तेमाल करते हैं। लेकिन कई बार हमें सिर्फ एक बहुत छोटा, एक-लाइन वाला function चाहिए होता है, जिसका कोई नाम भी जरूरी नहीं होता। ऐसी situation में Python का Lambda Function काम आता है।

Lambda Function एक anonymous function है — यानी बिना नाम वाला छोटा function, जिसे एक ही लाइन में लिखा जा सकता है।

अगर आपने अभी Functions Basics नहीं पढ़ा है, तो पहले Python Functions Basics in Hindi पढ़ें। Examples खुद run करने के लिए हमारा Online Python Editor & Compiler use कर सकते हैं।

🎥 Video में समझें

Lambda Function क्या है?

Lambda Function Python का एक ऐसा तरीका है जिससे बिना def keyword और बिना function name के एक छोटा function बनाया जा सकता है।

सरल भाषा में — Lambda एक छोटा, एक-लाइन वाला function है जिसका कोई नाम नहीं होता।
Example
square = lambda x: x * x print(square(5))

Output:

25
Try it Yourself »

Lambda Function का Syntax

Syntax
lambda arguments: expression
  • lambda → keyword जो function बनाने के लिए इस्तेमाल होता है
  • arguments → parameters, जितने चाहें उतने हो सकते हैं
  • : → arguments और expression को अलग करता है
  • expression → एक ही statement, जिसका result automatically return होता है
Note: Lambda function में return keyword नहीं लिखा जाता — expression का result अपने-आप return हो जाता है।

Anonymous Function क्या होता है?

Anonymous function वह function होता है जिसका कोई नाम नहीं होता। Lambda function एक anonymous function का उदाहरण है।

Example — बिना नाम के इस्तेमाल
print((lambda x: x * x)(5))

Output:

25

यहाँ function का कोई नाम नहीं दिया गया — इसे directly define करके तुरंत call कर दिया गया।

Try it Yourself »

Lambda Function को Variable में Store करना

Lambda function को नाम देने के लिए उसे किसी variable में assign किया जाता है।

Example
greet = lambda: print("Hello Python!")

यहाँ greet variable अब lambda function को refer कर रहा है।

Lambda Function को Call करना

Example
greet = lambda: print("Hello Python!") greet()

Output:

Hello Python!

Lambda function को उसी तरह call किया जाता है जैसे normal function को — variable name के बाद () लगाकर।

Try it Yourself »

बिना Argument वाला Lambda Function

Example
message = lambda: "Welcome to PythonHindii!" print(message())

Output:

Welcome to PythonHindii!
Try it Yourself »

One Argument वाला Lambda Function

Example
square = lambda x: x * x print(square(6))

Output:

36
Try it Yourself »

Multiple Arguments वाला Lambda Function

Example
add = lambda a, b: a + b print(add(10, 20))

Output:

30

Lambda function में comma से अलग करके जितने चाहें उतने arguments दिए जा सकते हैं।

Try it Yourself »
Example — तीन Arguments
total = lambda a, b, c: a + b + c print(total(10, 20, 30))

Output:

60
Try it Yourself »

Lambda Function से Simple Calculations

Example
multiply = lambda a, b: a * b subtract = lambda a, b: a - b print(multiply(5, 4)) print(subtract(10, 3))

Output:

20 7
Try it Yourself »

Practical Example — Discount Calculator

Example
discount_price = lambda price, discount: price - (price * discount / 100) final_price = discount_price(1000, 10) print("Final Price:", final_price)

Output:

Final Price: 900.0
Try it Yourself »

Practical Example — Function को Argument की तरह Pass करना

Example
def calculate(operation, a, b): return operation(a, b) result = calculate(lambda a, b: a + b, 10, 5) print(result)

Output:

15

यहाँ lambda function को बिना नाम दिए सीधे argument की तरह pass कर दिया गया — यही anonymous function होने का सबसे बड़ा फायदा है।

Try it Yourself »

Normal Function और Lambda Function में Difference

Normal Function (def)Lambda Function
Function का नाम होता हैBy default नाम नहीं होता (anonymous)
Multiple statements लिखे जा सकते हैंसिर्फ एक ही expression
return keyword जरूरी हैreturn लिखने की जरूरत नहीं
Complex logic के लिए बेहतरछोटे, simple operations के लिए बेहतर
कई लाइनों में लिखा जाता हैएक ही लाइन में लिखा जाता है
Example — दोनों का Comparison
def add_normal(a, b): return a + b add_lambda = lambda a, b: a + b print(add_normal(10, 5)) print(add_lambda(10, 5))

Output:

15 15

दोनों का result same है, लेकिन add_lambda सिर्फ एक लाइन में लिखा गया।

Try it Yourself »

Lambda Function की Limitations

  • सिर्फ एक expression — lambda में एक से ज्यादा statements नहीं लिखी जा सकतीं
  • if-else जैसी multi-line logic मुश्किल — बड़ी conditional logic के लिए normal function बेहतर है
  • Readability कम हो सकती है — complex lambda expressions पढ़ने में मुश्किल हो सकती हैं
  • Debugging कठिन — lambda function का कोई नाम न होने से error messages कम clear होते हैं
  • Loops नहीं लिखे जा सकते — lambda के अंदर for या while loop सीधे इस्तेमाल नहीं हो सकते
Note: Lambda function को हर जगह इस्तेमाल करना जरूरी नहीं — जहाँ logic simple और एक-लाइन में हो, वहीं इसका इस्तेमाल करना बेहतर होता है।

Common Lambda Mistakes

❌ return keyword लिख देना
square = lambda x: return x * x # SyntaxError
✅ सही तरीका
square = lambda x: x * x
❌ Multiple statements लिखने की कोशिश करना
calc = lambda x: x = x + 1; print(x) # SyntaxError
✅ सही तरीका — normal function इस्तेमाल करें
def calc(x): x = x + 1 print(x)
❌ Colon भूल जाना
square = lambda x x * x # SyntaxError
✅ सही तरीका
square = lambda x: x * x
❌ हर जगह lambda इस्तेमाल करना

अगर logic complex है या कई लाइनों में फैली है, तो lambda की जगह normal def function इस्तेमाल करना बेहतर है।

VS Code में Live Coding

VS Code में एक नई file lambda_demo.py बनाइए और यह code लिखिए:

lambda_demo.py
square = lambda x: x * x add = lambda a, b: a + b print(square(5)) print(add(10, 20))

File save करके VS Code के Terminal में इसे run कीजिए।

Terminal में Actual Output

$ python lambda_demo.py 25 30

पहली line square(5) से आई, और दूसरी line add(10, 20) से।

Quick Example — सब कुछ एक साथ

Example
greet = lambda: print("Hello!") square = lambda x: x * x add = lambda a, b: a + b total = lambda a, b, c: a + b + c greet() print(square(4)) print(add(5, 6)) print(total(1, 2, 3))

Output:

Hello! 16 11 6
Try it Yourself »

Exercise ?

Lambda function में किस keyword से value return होती है?

return keyword से
Expression अपने-आप return होती है
print keyword से

Final Coding Challenge

अब खुद अपने Online Python Editor या VS Code में यह challenge solve कीजिए:

  1. एक lambda function बनाइए जो किसी number का cube return करे।
  2. एक lambda function बनाइए जो दो numbers में से बड़ा number return करे।
  3. एक lambda function बनाइए जो किसी string की length return करे।
  4. एक lambda function बनाइए जो check करे कि कोई number even है या odd।
  5. एक normal function और उसका lambda version दोनों बनाकर उनका output compare कीजिए।

Quick Revision

Conceptमतलब
Lambda Functionबिना नाम वाला छोटा, एक-लाइन function
Anonymous Functionऐसा function जिसका कोई नाम नहीं होता
Syntaxlambda arguments: expression
ReturnAutomatic — return keyword की जरूरत नहीं
Best Useछोटी, simple calculations और quick operations

FAQ

Python में Lambda Function क्या है?

Lambda Function एक anonymous, एक-लाइन वाला function है जो lambda arguments: expression syntax से बनाया जाता है।

Lambda Function में return keyword क्यों नहीं लिखते?

क्योंकि lambda function में expression का result अपने-आप return हो जाता है, इसलिए return keyword लिखने की जरूरत नहीं होती।

क्या Lambda Function में multiple arguments हो सकते हैं?

हाँ। Lambda function में comma से अलग करके जितने चाहें उतने arguments दिए जा सकते हैं, जैसे lambda a, b, c: a + b + c।

Lambda Function और Normal Function में मुख्य फर्क क्या है?

Normal function def keyword से बनता है, उसका नाम होता है, और उसमें multiple statements लिखी जा सकती हैं। Lambda function anonymous होता है और सिर्फ एक ही expression रख सकता है।

Lambda Function कब इस्तेमाल करना चाहिए?

जब logic बहुत छोटा और simple हो, और किसी function को सिर्फ temporary तौर पर या किसी दूसरे function के argument की तरह इस्तेमाल करना हो, तब lambda function उपयोगी होता है।

Summary

Lambda = बिना नाम का, एक-लाइन में लिखा गया छोटा function।

इस article में आपने सीखा कि Lambda Function क्या है, इसका syntax क्या है, इसे variable में कैसे store और call करें, बिना argument, one argument और multiple arguments वाले lambda functions कैसे बनते हैं, Normal Function और Lambda Function में क्या difference है, और Lambda Function की limitations क्या हैं।

Lambda function छोटे और simple operations के लिए बहुत उपयोगी है, लेकिन complex logic के लिए normal def function ही बेहतर रहता है। अब ऊपर दिया गया coding challenge खुद VS Code या Online Editor में solve करें।

Related Articles

🧑‍💻 Python Coding Lab Python code likho, run karo aur practice karo — directly browser mein.