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
🎓 100% Free · Hindi me · Beginner se Career tak

Python Tutorial in HindiiLearn Python Programming for Free

Python, AI, Data Analytics aur SQL ek hi jagah, simple Hindi me. Padho, browser me code chalao, projects banao aur career shuru karo.

main.py
# Python seekho, Hindi me naam = "Ravi" for i in range(3): print("Namaste", naam)
▸ python main.py
🐍 Python 🤖 AI & ML 📊 Data 🗄️ SQL

Chahe Student ho ya Professional, yahan aapke liye sab hai

Apna card chuno, seedha sahi jagah pahunch jaoge.

🎓

Student ho?

School ya college me ho? Python zero se seekho, notes aur cheat sheets ke saath.

  • Python basics se OOP tak
  • Notes, PDFs aur Cheat Sheets
  • Browser me practice, kuch install nahi
💼

Working Professional ho?

Kaam ke saath nayi skill jodo: data, SQL aur AI se apna kaam tez karo.

  • Pandas, NumPy, Excel, Power BI
  • SQL aur MySQL databases
  • Automation aur AI Tools
🚀

Job ya Career change?

Projects banao, interview ki taiyari karo aur sahi roadmap follow karo.

  • Real projects, portfolio ke liye
  • Python aur SQL interview questions
  • AI Engineer, Data Scientist roadmap

Python Hindii Kaise Kaam Karta Hai?

Ek hi jagah 4 layers: seekho, practice karo, skills banao aur career shuru karo. Har layer ek step hai, us par click karke seedha wahan pahuncho. Computer par drag karke 3D me ghumao bhi.

Layer 1 · Seekho

Python Basics se Advanced tak

Variables, loops, functions se OOP tak, sab simple Hindi me. Yahin se shuru karo.

Naye ho? 3 step me shuru karo

💻 Online Code Editor

Browser me hi code likho aur turant chalao

Koi software install nahi. Code likho, Run dabao aur result usi waqt dekho.

  • Python, Java, C, C++, JavaScript, HTML aur aur bhi languages
  • input(), graphs aur multi-file HTML project bhi chalte hain
  • Mobile aur computer, dono par chalta hai
main.py
naam = input("Naam batao: ") for i in range(3): print("Namaste", naam)
▸ python main.py
PythonJavaCC++JavaScriptHTML

Python se AI tak ka poora rasta

8 steps, ek ke baad ek. Aage-peeche ghumao aur apni stage se seedha shuru karo.

Step 1 🐍

Python Basics

IntroductionVariablesData TypesOperatorsInput & OutputConditionsLoops
Start Python →
Step 2 💻

Python Intermediate

ListsTuplesSetsDictionariesStringsModulesFile Handling
Continue Python →
Step 4 🗄️

SQL & Databases

SQL BasicsMySQLSELECTINSERTUPDATEDELETEJOIN
Learn SQL →
Step 5 📊

Data Analytics

NumPyPandasData CleaningData VisualizationMatplotlibExploratory Data Analysis
Learn Data Analytics →
Step 6 🤖

Machine Learning

ML BasicsSupervised & Unsupervised LearningRegressionClassificationModel EvaluationScikit-learn
Learn Machine Learning →
Step 7 🧠

Artificial Intelligence

AI FundamentalsGenerative AIAI ToolsPrompt EngineeringLLM ConceptsAI Automation
Explore AI →
Step 8 🚀

Projects & Career

Python ProjectsAI ProjectsData ProjectsPortfolioGitHubInterview PreparationCareer Roadmap
Build Your Career →
Step 1 / 8

Python Constructor and __init__() Method Explained: A Complete Beginner's Guide

Python Constructor and init method Explained in Hindi

Python Constructor और __init__()

Object-Oriented Programming (OOP) में Object बनाते ही उसे शुरुआती वैल्यूज देना सबसे बुनियादी और जरूरी काम होता है। Python में इस काम को आसान और automatic बनाने के लिए एक special method होता है — __init__(), जिसे सामान्यतः Constructor कहा जाता है।

अगर आपने अभी तक Python Classes & Objects नहीं पढ़ा है, तो पहले उसे पढ़ना जरूरी है क्योंकि __init__() सीधे Class और Object के निर्माण से जुड़ा है। कोड को खुद चलाकर देखने के लिए आप हमारे Online Python Editor & Compiler का इस्तेमाल कर सकते हैं।

⚠️ इस Lesson का Scope: इस lesson में हम सिर्फ Constructor क्या है, __init__() का role, self की भूमिका, parameters पास करना, default values, और real-world examples (Employee, Mobile) को practical नजरिए से समझेंगे।

Constructor क्या है?

Constructor एक विशेष प्रकार का method (function) होता है, जो किसी Class का नया Object (Instance) बनते ही अपने-आप (automatically) execute हो जाता है। इसका मुख्य काम Object के अंदर जरूरी initial data (attributes) को set करना होता है।

सरल भाषा में — Constructor का मतलब है: "जब भी कोई नया Object जन्म लेगा, यह method बिना बुलाए खुद चलेगा और Object की बुनियादी तैयारी पूरी कर देगा।"

Python में __init__() क्या है?

Python में Constructor का काम __init__() method करता है। नाम के आगे और पीछे लगे दो underscores (__) यह दर्शाते हैं कि यह एक special method (Dunder Method) है।

Example — __init__() का Automatic Execution
class Demo: def __init__(self): print("Object create ho gaya!") # Object banate hi __init__() apne-aap chalega obj = Demo()

Output:

Object create ho gaya!

यहाँ हमने obj.__init__() को manually call नहीं किया। जैसे ही Demo() लिखा गया, यह method खुद-ब-खुद execute हो गया।

Try it Yourself »
Class Name Call: obj = Demo() │ ▼ (Automatically triggers) __init__(self) │ ▼ (Initializes attributes) Ready Object
🎥 Video में पूरा Topic समझें

self का Basic Role

Python में जब भी आप Class के अंदर methods बनाते हैं, पहला parameter हमेशा self होता है।

  • self वर्तमान में बन रहे current object को represent करता है।
  • जब आप self.name = name लिखते हैं, तो Python समझता है कि यह डेटा इसी खास object के अंदर स्टोर करना है।
  • Object बनाते समय आपको self के लिए कोई argument पास नहीं करना होता; Python इसे background में खुद handle करता है।

Without __init__() vs With __init__()

बिना __init__() के ऑब्जेक्ट का डेटा सेट करना लंबा और गलतियों से भरा होता है, जबकि __init__() के साथ यह काम एक ही लाइन में हो जाता है।

Example — बिना __init__() के (लंबा तरीका)
class Student: pass s1 = Student() s1.name = "Aman" # Har variable manually set karna padega s1.roll_no = 101 print(s1.name, s1.roll_no)

यहाँ अगर आप कोई variable सेट करना भूल गए, तो आगे चलकर कोड में AttributeError आ सकता है।

Example — __init__() के साथ (साफ और सुरक्षित तरीका)
class Student: def __init__(self, name, roll_no): self.name = name self.roll_no = roll_no s1 = Student("Aman", 101) # Object bante hi data initialize ho gaya print(s1.name, s1.roll_no)

Output:

Aman 101
Try it Yourself »

Parameters और Multiple Objects के साथ __init__()

हम __init__() में parameters pass करके एक ही Class से अलग-अलग data वाले कई objects बना सकते हैं:

Example — Multiple Objects
class Car: def __init__(self, brand, color): self.brand = brand self.color = color def show(self): print(f"Car: {self.brand}, Color: {self.color}") car1 = Car("Tata", "Red") car2 = Car("Mahindra", "Black") car1.show() car2.show()

Output:

Car: Tata, Color: Red Car: Mahindra, Color: Black

car1 और car2 दोनों एक ही Class से बने हैं, लेकिन self की वजह से दोनों का डेटा पूरी तरह अलग और सुरक्षित रहता है।

Try it Yourself »

Default Values के साथ __init__()

अगर कोई user object बनाते समय किसी argument की value नहीं देता, तो हम default parameter का उपयोग कर सकते हैं:

Example — Default Values
class User: def __init__(self, username, role="Student"): self.username = username self.role = role u1 = User("Rohan") # role default le lega u2 = User("Pooja", "Admin") # role override ho jayega print(u1.username, "-", u1.role) print(u2.username, "-", u2.role)

Output:

Rohan - Student Pooja - Admin
Try it Yourself »

Practical Examples: Mobile और Employee

आइए इसे दो real-world उदाहरणों से समझते हैं:

Example 1 — Mobile Phone
class Mobile: def __init__(self, brand, model, price): self.brand = brand self.model = model self.price = price def display_specs(self): print(f"Mobile: {self.brand} {self.model} | Price: ₹{self.price}") m1 = Mobile("Apple", "iPhone 15", 79900) m2 = Mobile("Samsung", "Galaxy S24", 74999) m1.display_specs() m2.display_specs()

Output:

Mobile: Apple iPhone 15 | Price: ₹79900 Mobile: Samsung Galaxy S24 | Price: ₹74999
Try it Yourself »
Example 2 — Company Employee
class Employee: def __init__(self, emp_id, name, salary): self.emp_id = emp_id self.name = name self.salary = salary def give_raise(self, percent): self.salary += self.salary * (percent / 100) print(f"{self.name} ki updated salary: ₹{self.salary}") emp1 = Employee(101, "Neeraj", 50000) emp1.give_raise(10)

Output:

Neeraj ki updated salary: ₹55000.0
Try it Yourself »

Common Beginner Mistakes

❌ Double Underscores की जगह Single Underscore लगाना
class Student: def _init_(self, name): # Single underscore kaam nahi karega self.name = name s = Student("Rahul") # TypeError: Student() takes no arguments
✅ सही तरीका
class Student: def __init__(self, name): # Aage-peeche do-do underscores (__) self.name = name
❌ self लिखना भूल जाना
class Demo: def __init__(name): # self missing hai pass d = Demo("Test") # Galat behavior ya runtime error
✅ सही तरीका
class Demo: def __init__(self, name): self.name = name
❌ __init__() से value return करने की कोशिश करना
class Student: def __init__(self, name): self.name = name return "Success" # TypeError: __init__() should return None
✅ सही तरीका

__init__() का काम केवल initialization करना होता है, यह कभी कोई custom value return नहीं कर सकता (केवल None return कर सकता है)।

Exercise ?

Python में __init__() method कब execute होता है?

A) जब हम उसे manually .init() लिखकर call करते हैं
B) जब Class का नया Object बनाया जाता है (Automatically)
C) जब प्रोग्राम खत्म होने वाला होता है

Practical Coding Challenge

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

  1. एक BankAccount Class बनाइए जिसमें __init__() method account_holder और balance (default value = 0) ले।
  2. पैसे जमा करने के लिए deposit(self, amount) method बनाइए जो balance में amount जोड़ दे।
  3. पैसे निकालने के लिए withdraw(self, amount) method बनाइए, जो तभी पैसे काटे जब balance पर्याप्त हो।
  4. दो अलग-अलग customers के objects बनाकर deposits और withdrawals टेस्ट कीजिए।

Quick Revision

Term / Conceptमतलब / काम
ConstructorObject बनते ही execute होने वाला automatic method
__init__()Python का built-in constructor method
selfCurrent object (instance) का reference
self.variable = valueObject के अंदर instance attribute बनाना और वैल्यू सेट करना
Default ParameterArgument न देने पर fallback वैल्यू सेट करना (उदा. role="User")
Return Value__init__() हमेशा None return करता है

FAQ

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

Constructor एक special method होता है जो Class का नया Object बनते ही अपने-आप run हो जाता है और Object के data को initialize करता है।

Python में __init__() का क्या काम है?

__init__() Python का constructor है, जिसका काम Object बनते समय उसके attributes (variables) में initial data set करना होता है।

__init__ के आगे और पीछे double underscores क्यों होते हैं?

ये underscores दर्शाते हैं कि यह Python का internal special method (Dunder method) है, जिसे Python खास मौकों पर (जैसे object creation) खुद call करता है।

क्या __init__() में self लिखना जरूरी है?

हाँ, self current instance को refer करता है। इसके बिना Python को यह पता नहीं चलेगा कि data किस object में store करना है।

क्या एक Class में एक से ज्यादा __init__() methods हो सकते हैं?

नहीं, Python method overloading को सीधे support नहीं करता। अगर आप एक से ज्यादा __init__() लिखेंगे, तो Python हमेशा आखिरी वाले को ही मानेगा।

Summary

__init__() = Object बनते ही अपने-आप चलने वाला setup method, जो data को initialize करता है।

इस lesson में आपने सीखा कि Constructor क्या होता है, __init__() कैसे काम करता है, self की क्या भूमिका है, parameters और default values कैसे पास किए जाते हैं, और real-world examples में इसका सही इस्तेमाल कैसे होता है।

अब ऊपर दिया गया BankAccount coding challenge अपने Online Editor में तुरंत solve करके अभ्यास करें।

Related Articles

🧑‍💻 Python Coding Lab

Python code likho, run karo aur practice karo — directly browser mein.