📘 Python में Function क्या है?
Table of Contents
ToggleLearn 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
def square(n):
return n*n
def greet(name):
print("Hello", name)
🎯 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 बन सकें।
print(len([1,2,3]))
def greet(name):
return "Hello " + name
def fact(n):
return 1 if n==0 else n*fact(n-1)
square = lambda x: x*x
list(map(lambda x:x*x,[1,2,3]))
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 तरीके से समझाएगा।
def area(l, w):
return l * w
area(5,3)
book(title="Python", year=2024)
def greet(name="User"):
print(name)
def add(*nums):
return sum(nums)
def info(**data):
print(data)
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 सीखेंगे।
def calculate_total():
pass
def greet(name):
"""Return greeting"""
return "Hi " + name
def add(a:int,b:int)->int:
return a+b
def add(x):
return x+1
def clean():
pass
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
🚀 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 बनाने में मदद करते हैं।
def outer(name):
def inner():
print(name)
inner()
def multi(n):
return lambda x: x*n
def debug(f):
return f
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
📊 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 बना सकते हैं।
def clean(x):
return str(x).strip().lower()
df["name"] = df["name"].apply(clean)
df["income"] = df["salary"]/df["members"]
df.groupby("city").sum()
usd*83
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
🔟 Python Function Examples
Learn Python functions with real-world examples and outputs. Perfect for beginners to practice coding step-by-step.
def say_hello():
print("Hello World!")
say_hello()
def add(a, b):
return a + b
print(add(3, 4))
def check_even(n):
return "Even" if n%2==0 else "Odd"
def fact(n):
result=1
for i in range(1,n+1):
result*=i
return result
def rev(s):
return s[::-1]
def max3(a,b,c):
return max(a,b,c)
def count_vowels(s):
return sum(1 for ch in s if ch in "aeiou")
def is_prime(n):
if n<=1: return False
for i in range(2,n):
if n%i==0:
return False
return True
def power(a,b):
return a**b
def greet(name):
print("Hello",name)
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
❓ 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
🚀 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)
📊 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
🚀 Data Science या Data Analytics सीखें
Real-world projects के साथ Python, Data Analytics और Data Science सीखें — beginner से job-ready बनें।
📞 Call Now: +91 94117 78145 | 📍 Dehradun, Uttarakhand
📝 Python Functions Quiz
1. Python function keyword क्या है?
2. Function call कैसे करते हैं?
3. Return keyword क्या है?
👉 Show Answers
✅ 2: myfunc()
✅ 3: return
📚 Related Learning Path
Step-by-step roadmap for Data & AI
Student Success Stories – Vista Alumni Achievements
Real students. Real transformations. From beginners to professionals.
🏅 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.
🚀 Start Your Data Career Today
Call or WhatsApp us now to book your seat in the next batch
