Function in Python in Hindi tutorial with examples

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

Learn function in Python in Hindi with definition, syntax, examples and real-life explanation.

📖 परिभाषा (Definition)

Python में फ़ंक्शन (Function) एक reusable block of code होता है जो किसी specific task को perform करता है। Function की मदद से हम code को बार-बार use कर सकते हैं, जिससे program efficient और readable बनता है।

🧮 Real-life Analogy

सोचिए आपके पास एक Calculator है। उसमें multiply (×) बटन दबाते ही multiplication हो जाता है। इसी तरह Python में function एक ऐसा block होता है जो हर बार call करने पर वही काम करता है।

⚙️ Python Function Syntax

def function_name(parameters):
    # Code Block
    return result
    
  • def keyword function define करने के लिए use होता है
  • ✔ Function name meaningful होना चाहिए
  • ✔ Parameters optional होते हैं
  • return result वापस देता है

📝 Example: Python Function

def greet():
    print("नमस्ते, Vista Academy में आपका स्वागत है!")

greet()
    

👉 यहाँ greet() एक simple function है। 👉 जब इसे call किया जाता है, यह message print करता है। 👉 इससे समझ आता है कि Python में function कैसे काम करता है।

अगर आप Python function in Hindi सीखना चाहते हैं, तो यह guide आपको basics से लेकर practical examples तक पूरी understanding देता है। Beginners के लिए यह सबसे आसान तरीका है function को समझने का।

🛠️ Function Basics — Parameters, Return & Arguments

Learn how Python functions work with parameters, return values, default and keyword arguments in simple Hindi.

इस सेक्शन में हम समझेंगे कि Python function में input कैसे दिया जाता है (arguments), output कैसे मिलता है (return), और default व keyword arguments कैसे use होते हैं।

📥 Parameters vs Arguments

Parameter function definition में placeholder होता है, और Argument function call के समय दी गई value होती है।

def add(a, b):
    return a + b

print(add(5, 7))  # Output: 12
    

🔁 Return Statement

return function से value वापस देता है। अगर return नहीं होगा तो output None होगा।

def multiply(a, b):
    return a * b

res = multiply(4, 5)
print(res)  # Output: 20
    

🆚 With Return vs Without Return

With Return
def square(n):
    return n*n
        
Value reuse कर सकते हैं
Without Return
def greet(name):
    print("Hello", name)
        
Sirf print करता है

🎯 Default Parameters

Default value use होती है जब argument pass नहीं किया जाता।

def greet(name="Student"):
    print("नमस्ते", name)

greet()
greet("Yogesh")
    

🔖 Keyword Arguments

Named arguments use करने से order important नहीं रहता।

def student(name, age, course):
    print(name, age, course)

student(age=22, course="Python", name="Radha")
    

✨ *args & **kwargs

Multiple values handle करने के लिए *args और **kwargs use होते हैं।

def info(name, *scores, **details):
    print(name, scores, details)

info("Aman", 78, 82, city="Delhi")
    

🧩 Practice

  • is_even(n) → even/odd check करें
  • avg(*nums) → average निकालें
  • greet() → default name add करें

Python basics समझने के लिए पढ़ें 👉 Python basics in Hindi guide

🌍 Scope in Python Functions (Local & Global)

Understand local, global and nonlocal variables in Python functions with simple Hindi examples.

Python में scope का मतलब है कि कोई variable कहाँ तक accessible है। Function के अंदर बना variable बाहर access नहीं होता (local), जबकि global variable पूरे program में accessible होता है।

📍 Local Variable

Function के अंदर बना variable सिर्फ उसी function में काम करता है।

def my_func():
    x = 10
    print("Inside:", x)

my_func()
print(x)  # Error
    

🌐 Global Variable

Global variable पूरे program में accessible होता है।

x = 50

def show():
    print(x)

show()
print(x)
    

📝 global Keyword

Function के अंदर global variable को modify करने के लिए global keyword use होता है।

x = 10

def update():
    global x
    x = x + 5

update()
print(x)
    

🔄 nonlocal Keyword

Nested function में outer variable को modify करने के लिए nonlocal use होता है।

def outer():
    x = 5
    def inner():
        nonlocal x
        x += 10
    inner()
    print(x)

outer()
    

✅ Best Practices

  • Local variables ज्यादा use करें
  • Global variables avoid करें
  • global / nonlocal carefully use करें
  • Clear variable naming रखें

🧩 Practice Questions

  • Local variable error example बनाओ
  • Global counter function बनाओ
  • nonlocal का nested example बनाओ

Python loops भी सीखें 👉 While Loop Practice Questions

🔍 Types of Functions in Python

Learn all types of functions in Python in Hindi — built-in, user-defined, recursive, lambda and higher-order functions with examples.

Python में कई प्रकार के functions होते हैं — कुछ built-in होते हैं और कुछ हम खुद बनाते हैं। इन सभी को समझना जरूरी है ताकि आप programming में expert बन सकें।

🧩 Built-in Functions
Python में पहले से available functions जैसे len(), sum(), max()
print(len([1,2,3]))
      
✍️ User-defined
Developer द्वारा बनाए गए custom functions
def greet(name):
    return "Hello " + name
      
🔁 Recursive
Function जो खुद को call करता है
def fact(n):
    return 1 if n==0 else n*fact(n-1)
      
λ Lambda
One-line anonymous function
square = lambda x: x*x
      
🔗 map / filter
Data transformation functions
list(map(lambda x:x*x,[1,2,3]))
      
⚡ reduce
Multiple values को single output में बदलता है
from functools import reduce
      

🧭 कब कौन सा function use करें?

  • Built-in: quick operations
  • User-defined: custom logic
  • Recursive: complex problems
  • Lambda: short operations

🧩 Practice

  • Lambda से square function बनाओ
  • filter से even numbers निकालो
  • Recursive factorial function बनाओ

Python basics सीखने के लिए पढ़ें 👉 Data Analytics Guide

🎯 Function Arguments in Python

Learn positional, keyword, default, *args and **kwargs in Python functions with easy Hindi examples.

Python में function arguments का मतलब है function को input देना। यह section आपको हर प्रकार के arguments को simple तरीके से समझाएगा।

1️⃣ Positional
Order के अनुसार arguments pass होते हैं
def area(l, w):
    return l * w
area(5,3)
      
2️⃣ Keyword
Parameter name के साथ value देते हैं
book(title="Python", year=2024)
      
3️⃣ Default
Default value set होती है
def greet(name="User"):
    print(name)
      
4️⃣ *args
Multiple values (tuple)
def add(*nums):
    return sum(nums)
      
5️⃣ **kwargs
Named values (dictionary)
def info(**data):
    print(data)
      
6️⃣ Mixing
सभी types combine कर सकते हैं
def f(a,*args,**kwargs):
    pass
      

⚠️ Important Tip

Mutable default arguments (list/dict) avoid करें — यह unexpected results दे सकते हैं।

def add_item(x, lst=None):
    if lst is None:
        lst=[]
    lst.append(x)
    return lst
    

🧩 Practice

  • Function बनाओ जो numbers का sum करे (*args)
  • Function बनाओ जो user info store करे (**kwargs)
  • Default argument का example बनाओ

Python functions basics पढ़ें 👉 Function in Python Guide

🧭 Python Function Best Practices

Learn how to write clean, readable and professional Python functions with best practices in Hindi.

अच्छे Python functions सिर्फ काम नहीं करते — वे readable, maintainable और scalable होते हैं। इस section में हम industry-level best practices सीखेंगे।

🔤 Naming
Meaningful names use करें (PEP8 style)
def calculate_total():
    pass
      
📚 Docstring
Function का description लिखें
def greet(name):
    """Return greeting"""
    return "Hi " + name
      
🔎 Type Hints
Code readability improve करें
def add(a:int,b:int)->int:
    return a+b
      
⚖️ Pure Function
Side effects avoid करें
def add(x):
    return x+1
      
🧩 Modular Code
छोटे functions बनाएं
def clean():
    pass
      
🧪 Testing
Unit test लिखें
assert add(2,3)==5
      

⚡ Performance Tips

  • Large data के लिए optimized functions use करें
  • Recursion में memoization use करें
  • Vectorized operations prefer करें

✅ Checklist

  • Clear name
  • Docstring added
  • Short function
  • No side effects

Master Python with Projects 🚀

Learn real-world coding with our course

Join Course

🚀 Advanced Functions in Python

Learn nested functions, closures, decorators and recursion in Python with practical Hindi examples.

Python में advanced functions आपको real-world coding और data analytics projects में powerful solutions बनाने में मदद करते हैं।

📦 Nested Function
Function के अंदर function
def outer(name):
    def inner():
        print(name)
    inner()
      
🔒 Closure
Function memory retain करता है
def multi(n):
    return lambda x: x*n
      
🎀 Decorator
Function behavior modify करता है
def debug(f):
    return f
      
🔁 Recursion
Function खुद को call करता है
def fact(n):
    return 1 if n==0 else n*fact(n-1)
      

🔧 Example: Closure

def make_multiplier(n):
    def inner(x):
        return x*n
    return inner
    

🎀 Example: Decorator

def debug(func):
    def wrapper(*args):
        print("Calling")
        return func(*args)
    return wrapper
    

🧭 कब use करें?

  • Closure → reusable logic
  • Decorator → logging, authentication
  • Recursion → complex problems

🧩 Practice

  • Closure से power function बनाओ
  • Decorator बनाओ जो time measure करे
  • Recursive binary search बनाओ

Build Real Python Projects 🚀

Learn advanced coding with real-world examples

Start Learning

📊 Functions in Data Analytics

Learn how Python functions are used in data cleaning, transformation and real-world analytics projects.

Data analytics में functions का use data cleaning, transformation और automation के लिए किया जाता है। छोटे reusable functions बनाकर आप powerful data pipelines बना सकते हैं।

🧹 Data Cleaning
Text clean करना, null handle करना
def clean(x):
    return str(x).strip().lower()
      
🔄 Transformation
Data modify और convert करना
df["name"] = df["name"].apply(clean)
      
🧠 Feature Engineering
New columns create करना
df["income"] = df["salary"]/df["members"]
      
📈 Aggregation
Group data और summarize करना
df.groupby("city").sum()
      
💱 Conversion
Currency / units convert करना
usd*83
      
🔁 Pipeline
Multiple steps automate करना
clean → transform → save
      

🧹 Example: Data Cleaning Function

def clean_text(x):
    if x is None:
        return None
    return str(x).strip().lower()
    

⚡ Performance Tips

  • Vectorized operations use करें (fast)
  • apply() only when needed
  • Large data के लिए optimized functions use करें

Learn Data Analytics with Python 🚀

Build real-world projects and get job-ready

Join Data Analyst Course

🔟 Python Function Examples

Learn Python functions with real-world examples and outputs. Perfect for beginners to practice coding step-by-step.

1️⃣ Hello Function
def say_hello():
    print("Hello World!")

say_hello()
      
Output: Hello World!
2️⃣ Sum Function
def add(a, b):
    return a + b

print(add(3, 4))
      
Output: 7
3️⃣ Odd / Even
def check_even(n):
    return "Even" if n%2==0 else "Odd"
      
Output: Odd
4️⃣ Factorial
def fact(n):
    result=1
    for i in range(1,n+1):
        result*=i
    return result
      
Output: 120
5️⃣ Reverse String
def rev(s):
    return s[::-1]
      
Output: nohtyP
6️⃣ Max Value
def max3(a,b,c):
    return max(a,b,c)
      
Output: 12
7️⃣ Count Vowels
def count_vowels(s):
    return sum(1 for ch in s if ch in "aeiou")
      
Output: 2
8️⃣ Prime Check
def is_prime(n):
    if n<=1: return False
    for i in range(2,n):
        if n%i==0:
            return False
    return True
      
Output: True
9️⃣ Power Function
def power(a,b):
    return a**b
      
Output: 8
🔟 Greeting
def greet(name):
    print("Hello",name)
      
Output: Hello Ravi

These Python function examples help beginners understand real coding use-cases. Practice these examples to master Python functions easily.

Practice Python Like a Pro 🚀

Learn coding with real-world projects

Join Python Course

❓ Python Function FAQs

Python functions se जुड़े common questions और उनके simple Hindi answers — beginners ke liye quick guide.

👉 Python में Function क्या होता है?

Function एक reusable code block होता है जो specific task perform करता है। इससे code clean, reusable और structured बनता है।

👉 Parameters और Arguments में क्या फर्क है?

Parameter function definition में होता है, जबकि argument function call के समय दी गई value होती है। Example: def f(x) → parameter, f(5) → argument

👉 क्या function में loop use कर सकते हैं?

हाँ, function के अंदर loops (for, while) और conditions use कर सकते हैं। इससे complex tasks को automate किया जा सकता है।

👉 क्या function multiple values return कर सकता है?

हाँ, Python में function multiple values return कर सकता है — ये internally tuple के रूप में आते हैं। Example: return a, b

👉 कौन सा keyword function define करने के लिए use होता है?

Python में function define करने के लिए def keyword use होता है।

👉 कितने types के functions होते हैं?

मुख्यतः built-in और user-defined functions होते हैं। इसके अलावा lambda, recursive आदि भी होते हैं।

👉 Python में lambda function क्या होता है?

Lambda function एक anonymous function होता है जो एक line में define होता है।

ये FAQs Python function in Hindi, types of functions, arguments और examples से जुड़े सभी common questions को cover करते हैं।

Master Python with Experts 🚀

Start your journey in Data Analytics today

Join Course

🚀 Capstone Project — Unit Converter CLI

Build a real-world Python project using functions. Learn temperature, distance and currency conversion with modular coding.

इस project में आप Python functions का real-world use सीखेंगे। यह project data analytics और automation projects की foundation बनाता है।

🎯 Project Objectives

  • Reusable Python functions बनाना
  • CLI (Command Line Interface) से input लेना
  • Invalid input handle करना

💻 Code Example

# converters.py
def c_to_f(c): return (c * 9/5) + 32
def f_to_c(f): return (f - 32) * 5/9

def ft_to_cm(ft): return ft * 30.48
def km_to_m(km): return km * 1000

RATE_USD_INR = 83.25
def usd_to_inr(usd, rate=RATE_USD_INR):
    return round(usd * rate, 2)
    
📦 Module
converters.py (functions)
🖥️ CLI Script
User input handling
📄 README
Usage instructions

📊 Evaluation Criteria

  • Modularity — 3 Marks
  • Correctness — 3 Marks
  • CLI usability — 2 Marks
  • Code quality — 2 Marks

This Python project helps you understand how functions are used in real-world applications like data analytics, automation and software development.

Build Real Projects & Get Job Ready 🚀

Learn Python + Data Analytics with practical training

Join Course

🚀 Data Science या Data Analytics सीखें

Real-world projects के साथ Python, Data Analytics और Data Science सीखें — beginner से job-ready बनें।

📊 Practical Training
100% hands-on learning
💼 Placement Support
Interview + resume help
📁 Live Projects
Real business case studies

📞 Call Now: +91 94117 78145 | 📍 Dehradun, Uttarakhand

📝 Python Functions Quiz

1. Python function keyword क्या है?



2. Function call कैसे करते हैं?


3. Return keyword क्या है?


👉 Show Answers
✅ 1: def
✅ 2: myfunc()
✅ 3: return

Student Success Stories – Vista Alumni Achievements

Real students. Real transformations. From beginners to professionals.

🎓 Anjali Verma
Commerce → Data Analyst at Accenture.
👨‍💻 Rohit Rawat
BPO → BI Executive (Python + Power BI).
📊 Meena Joshi
Career switch → Remote Data Consultant.
👨‍🏫 Chandresh Aggarwal
Faculty at Invertis University.
🏦 Siddharth Mall
Data Analyst at IndusInd Bank.
🤖 Akash Singh
Junior Data Scientist at Capgemini.
📈 Taruna
Data Visualization Expert at RMSI.
🏭 Ramandeep Singh
MIS Executive at Ambuja Cement.
💼 Abhishek
Python Automation → Clarivoyance IT.
🌟 Asfi Mahim
Junior Data Analyst at Guardian One Brands.

🏅 Vista Academy Gallery

Certified Data Analyst Program

🎓 Every certificate tells a success story.

🚀 Start Your Data Career Today

Call or WhatsApp to book your seat in the next batch

Ready to Start Your Data Analytics Career?

Learn industry tools. Build real dashboards. Crack interviews. Join Vista Academy – Dehradun’s trusted Data, AI & Analytics institute.

Next Batch
Limited Seats
Small batches ensure personal mentorship.
Mode
Offline + Live Online
Classroom in Dehradun & remote learning across Uttarakhand.

🚀 Start Your Data Career Today

Call or WhatsApp us now to book your seat in the next batch

Vista Academy – 316/336, Park Rd, Laxman Chowk, Dehradun – 248001
📞 +91 94117 78145 | 📧 thevistaacademy@gmail.com | 💬 WhatsApp
💬 Chat on WhatsApp: Ask About Our Courses