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 →

Python Inner Functions in Hindi | Function inside Function Tutorial

Python Inner Functions in Hindi - Function inside Function Tutorial

Python Inner Functions

Python में हम function के अंदर सिर्फ code ही नहीं, बल्कि दूसरा function भी define कर सकते हैं। जब किसी function के अंदर एक और function बनाया जाता है, तो उसे Inner Function (या Nested Function) कहा जाता है।

यह concept थोड़ा unusual लग सकता है, लेकिन real-world programming में इसका इस्तेमाल code को organize करने और किसी logic को सिर्फ एक जगह तक सीमित रखने के लिए किया जाता है।

अगर आपने अभी Functions Basics नहीं पढ़ा है, तो पहले Global vs Local Variables in Python पढ़ना उपयोगी रहेगा, क्योंकि Inner Function को समझने के लिए scope का concept जानना जरूरी है। Examples खुद run करने के लिए हमारा Online Python Editor & Compiler use कर सकते हैं।

🎥 Video में पूरा Topic समझें

Inner Function क्या है?

जब किसी function के अंदर एक और function define किया जाता है, तो उस अंदर वाले function को Inner Function कहते हैं।

सरल भाषा में — Function के अंदर बना हुआ function ही Inner Function है।
Example
def outer(): print("Outer Function") def inner(): print("Inner Function") inner() outer()

Output:

Outer Function Inner Function
Try it Yourself »

Function के अंदर Function कैसे बनाते हैं?

Inner function बनाने के लिए, outer function के body के अंदर ही def keyword से एक और function define कर दिया जाता है — बिल्कुल उसी तरह जैसे normal function बनाते हैं, बस इसे किसी दूसरे function के अंदर रखा जाता है।

Syntax
def outer_function(): # outer का code def inner_function(): # inner का code inner_function()
Note: Indentation पर ध्यान दें — inner function outer function के body के अंदर ही indent होना चाहिए, वरना वह normal (अलग) function बन जाएगा।

Outer Function और Inner Function क्या होते हैं?

Termमतलब
Outer Functionबाहर वाला function, जिसके अंदर दूसरा function define किया गया है
Inner FunctionOuter function के अंदर बना हुआ function
Example
def greet_user(): # Outer Function print("Welcome!") def show_name(): # Inner Function print("Hello Python!") show_name() greet_user()

Output:

Welcome! Hello Python!
Try it Yourself »

Inner Function को Call कैसे करें?

Inner function को सिर्फ outer function के अंदर से ही call किया जा सकता है, क्योंकि यह outer function के local scope में define होता है।

Example
def outer(): def inner(): print("Inner function called") inner() # यहाँ call करना सही है outer()

Output:

Inner function called
Try it Yourself »
Example — यह error देगा
def outer(): def inner(): print("Inner function") outer() inner() # NameError: name 'inner' is not defined

Outer function के बाहर से inner() को directly call नहीं किया जा सकता, क्योंकि वह outer function के scope से बाहर existing ही नहीं करता।

Inner Function में Arguments का उपयोग

Inner function भी normal function की तरह arguments ले सकता है।

Example
def outer(name): def inner(greeting): print(greeting, name) inner("Namaste") outer("Ankit")

Output:

Namaste Ankit

यहाँ inner() को अपना argument greeting मिला, और outer के parameter name को भी access कर लिया।

Try it Yourself »

Inner Function से Value Return करना

Inner function भी किसी normal function की तरह return statement से value वापस दे सकता है।

Example
def outer(a, b): def inner(): return a + b result = inner() return result print(outer(10, 20))

Output:

30

यहाँ inner() ने calculation करके result return किया, और outer function ने उस result को आगे return कर दिया।

Try it Yourself »

एक Outer Function में Multiple Inner Functions

एक ही outer function के अंदर एक से ज्यादा inner functions भी बनाए जा सकते हैं।

Example
def calculator(a, b): def add(): return a + b def subtract(): return a - b print("Sum:", add()) print("Difference:", subtract()) calculator(10, 5)

Output:

Sum: 15 Difference: 5

दोनों inner functions add() और subtract() outer function के parameters a और b को access कर पाए।

Try it Yourself »

Inner Function द्वारा Outer Function के Variable को Access करना

Inner function अपने outer function के variables को directly read कर सकता है, बिना उन्हें फिर से पास किए।

Example
def outer(): message = "Hello from Outer!" def inner(): print(message) # outer के variable को access किया inner() outer()

Output:

Hello from Outer!
Try it Yourself »
Note: Inner function outer के variable को read कर सकता है, लेकिन उसे directly modify करने के लिए nonlocal keyword की जरूरत पड़ती है — यह concept आगे Closures और Decorators में detail में समझाया जाएगा।

Inner Function का Basic Scope

Inner function का scope outer function के अंदर तक ही सीमित होता है — यही scope की सबसे जरूरी बात है।

क्या हो सकता है?संभव है क्या
Inner function, outer के variables को read कर सकता हैहाँ
Outer function, inner के अंदर बने local variables को access कर सकता हैनहीं
Inner function को outer के बाहर से directly call किया जा सकता हैनहीं
एक outer function में multiple inner functions हो सकते हैंहाँ
Example — Scope को समझें
def outer(): def inner(): value = 100 print(value) inner() print(value) # यह error देगा outer()

Inner function के अंदर बना value variable सिर्फ inner() के अंदर ही accessible है — outer function उसे access नहीं कर सकता।

Practical Example — Discount Calculator

Example
def price_calculator(price): def apply_discount(discount_percent): discount = price * discount_percent / 100 return price - discount final_price = apply_discount(10) return final_price print(price_calculator(1000))

Output:

900.0

यहाँ apply_discount() एक inner function है जो outer function के price variable को access करके discount calculate कर रहा है।

Try it Yourself »

Practical Example — Validation Logic को अलग रखना

Example
def process_marks(marks): def is_valid(m): return 0 <= m <= 100 if is_valid(marks): print("Valid marks:", marks) else: print("Invalid marks!") process_marks(85) process_marks(150)

Output:

Valid marks: 85 Invalid marks!

यहाँ is_valid() जैसा छोटा helper logic सिर्फ process_marks() के अंदर ही जरूरी है, इसलिए उसे inner function बना दिया गया — बाहर से इस्तेमाल करने की जरूरत नहीं।

Try it Yourself »

Common Beginner Mistakes

❌ Inner Function को बाहर से call करने की कोशिश
def outer(): def inner(): print("Hi") outer() inner() # NameError
✅ सही तरीका
def outer(): def inner(): print("Hi") inner() outer()
❌ Inner Function को Call करना भूल जाना
def outer(): def inner(): print("Hello") # inner() call ही नहीं किया outer() # कोई output नहीं
✅ सही तरीका
def outer(): def inner(): print("Hello") inner() outer()
❌ Indentation गलत रखना
def outer(): print("Outer") def inner(): # यह अलग, independent function बन गया print("Inner")

यहाँ inner() outer function के अंदर नहीं है, क्योंकि indentation match नहीं हो रहा — यह एक normal, अलग function है।

❌ Outer Variable को बिना nonlocal के Modify करने की कोशिश
def outer(): count = 0 def inner(): count = count + 1 # UnboundLocalError inner()

Outer variable को सिर्फ read करना ठीक है, लेकिन उसे modify करने के लिए nonlocal keyword की जरूरत होती है, जो एक advanced concept है।

Exercise ?

Inner Function को किस जगह से call किया जा सकता है?

Program में कहीं से भी
सिर्फ अपने Outer Function के अंदर से
किसी दूसरे function से

Coding Challenges

अब खुद अपने Online Python Editor में इन challenges को solve कीजिए:

  1. एक outer function बनाइए जिसके अंदर एक inner function हो जो "Hello from Inner!" print करे।
  2. एक outer function बनाइए जो दो numbers ले, और एक inner function उनका multiplication करके return करे।
  3. एक outer function के अंदर दो inner functions बनाइए — एक square निकाले, दूसरा cube निकाले।
  4. एक outer function बनाइए जिसमें एक variable हो, और inner function उस variable को access करके print करे।
  5. एक bill_calculator(amount) function बनाइए जिसके अंदर एक inner function add_tax() हो, जो 18% tax जोड़कर final amount return करे।

Quick Revision

ConceptMeaning
Inner Functionकिसी function के अंदर define किया गया function
Outer Functionवह function जिसके अंदर inner function मौजूद है
Call करने का तरीकासिर्फ outer function के अंदर से
Outer Variable AccessRead किया जा सकता है, बिना extra code के
Outer Variable Modifynonlocal keyword चाहिए

FAQ

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

Inner Function वह function है जो किसी दूसरे function (outer function) के अंदर define किया जाता है।

क्या Inner Function को outer function के बाहर से call कर सकते हैं?

नहीं। Inner Function outer function के local scope में होता है, इसलिए उसे सिर्फ outer function के अंदर से ही call किया जा सकता है।

क्या Inner Function, Outer Function के variables को access कर सकता है?

हाँ। Inner Function अपने outer function के variables को directly read कर सकता है। उन्हें modify करने के लिए nonlocal keyword की जरूरत होती है।

एक Outer Function में कितने Inner Functions हो सकते हैं?

एक outer function के अंदर जरूरत के अनुसार एक से ज्यादा inner functions define किए जा सकते हैं।

Inner Function इस्तेमाल करने का फायदा क्या है?

Inner Function से helper logic को उसी function तक सीमित रखा जा सकता है, जिससे code organized रहता है और बाकी program में unnecessary functions नहीं बनते।

Summary

Inner Function = किसी function के अंदर बना हुआ छोटा function, जो सिर्फ उसी के अंदर काम आता है।

इस article में आपने सीखा कि Inner Function क्या है, इसे कैसे बनाते और call करते हैं, इसमें arguments और return कैसे काम करते हैं, एक outer function में multiple inner functions कैसे बनाए जाते हैं, और inner function outer के variables को कैसे access करता है।

Inner Functions code को organize रखने और किसी logic को सिर्फ जरूरी जगह तक सीमित रखने का अच्छा तरीका हैं। यह concept आगे चलकर Closures और Decorators को समझने की नींव भी बनता है। अब ऊपर दिए गए coding challenges खुद अपने Online Editor में solve करें।

Related Articles

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