Table of Contents
Python Tutorial
Table of Contents
Python Tutorial
Python Classes and Objects in Hindi
What is Python Classes and Objects
Classes and Objects किसी भी Object-Oriented Programming के core concepts होते है, इस tutorial मे हम समझेंगे की Python मे Classes and Objects का use कैसे किए जाता है।
What is Class in Python
एक class किसी object का blueprint होता है, ये object के structure and behavior को define करता है। एक class मे variables and functions define होते है।
How to Create a Class in Python
किसी class को create करने के लिए “class” keyword का use किया जाता है।
Attributes : class के अंदर जो variable create किए जाते है उन्हे attributes कहा जाता है। attributes के 2 types होते है,
- Class Attributes : ऐसे attributes जो class के अंदर लेकिन methods के बाहर create किए जाते है उन्हे class attributes कहा जाता है, ये सभी objects के लिए same होते है।
- Instance Attributes : ऐसे attributes जो किसी class के methods मे create किए जाते है उन्हे Instance attributes कहा जाता है, ये हर objects के लिए अलग-अलग हो सकते है।
Constructor : constructor वो method होता है जिससे python को पता चलता है की कोई भी class कहा से start हो रहा है, python मे एक method होता है __init__ जिसे constructor कहा जाता है, ये एक Dunder Method है इसलिए जब हम object को बनाते है तो __init__ method automatic call हो जाता है, इसका use किसी object को initialize करने के लिए किया जाता है।
Self : जब हम किसी class का object create करते है तो python automatically उस object को class मे as a argument pass कर देता है, कर देता है, जिसके लिए हमे हर method मे एक self parameter बनाना होता है but आप self की जगह कोई भी valid word लिख सकते है, आमतौर पर सिर्फ self का ही use किया जाता है।
Methods : class के अंदर जो भी functions define किए जाते है उन्हे methods कहा जाता है, ये 3 types के होते है,
- Instance Methods : ऐसे methods जो object के साथ काम करते है, उन्हे instance method कहते है। इसमे सबसे पहला parameter “self” होता है।
- Class Methods : ऐसे methods जो class के साथ काम करते है, उन्हे class method कहते है। इसमे सबसे पहला parameter “cls” (Class) होता है। class method को create करने के लिए @classmethod decorator का use करते है।
- Static Methods : ये method किसी भी class या instance से नहीं जुड़े होते है और ना ही कोई special parameter ( जैसे self या cls ) लेते है। static method को create करने के लिए @staticmethod decorator का use करते है।
SYNTAX :
class ClassName:
# Class attributes
# Constructor
def __init__(self, parameters):
# Instance attributes
# Methods
def method_name(self):
# Method body
What is Object in Python
Object किसी class का instance होता है। ये class के structure और behavior के हिसाब से work करता है।
Object को create करने के लिए Class के Constuctor को call किया जाता है।
Object के Attributes और Methods को access करने के लिए dot notation ( . ) का use किया जाता है।
SYNTAX :
object_name = ClassName(arg1, arg2)
Some Important Points of Classes and Objects
Modify Object Properties
हम object के properties को directly modify कर सकते है, इसके लिए हमे dot notation ( . ) का use करना होता है।
Del Keyword
del keyword का use करके हम किसी भी object या object properties को delete कर सकते है।
Pass Keyword
जब हम कोई empty class या function को create करते है तो यह error देता है, but हम pass keyword का use करके error को avoid कर सकते है।
उम्मीद करते है कि आपको Python Classes and Objects अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,
- All Posts
- Artificial Intelligence
- Computer Fundamentals
- Computer Networks
- Data Analytics
- Data Science
- DBMS
- Deep Learning
- Digital Electronics
- DSA with Python
- Excel
- Exercise
- Git & Github
- Machine Learning
- Matplotlib
- Natural Language Processing
- NumPy
- Operating System
- Pandas-s
- Power BI
- Python Tutorial
- Scikit-learn
- Seaborn
- SQL & MySQL

Table of Contents All Chapters 1. Personal Area Network 2. Local Area Network 3. Campus Area Network 4. Metropolitan Area...

Table of Contents All Chapters 1. Data Communication 2. Types of Data Communication 2.1. Simplex 2.2....

Table of Contents All Chapters 1. Special Logic Gate 2. XOR Gate 2.1. XOR Gate Truth Table 3....

Table of Contents All Chapters 1. Universal Logic Gates 2. NOR Gate 2.1. NOR Gate Truth Table 3....

Table of Contents All Chapters 1. Logic Gate 2. AND Gate 2.1. AND Gate Truth Table 3. OR...

Table of Contents All Chapters 1. Simplification 2. Simplification using Boolean Algebra Theorems 3. Simplification using K-map Digital Electronics...

Table of Contents All Chapters 1. Identity Laws 2. Null Laws 3. Domination Laws 4. Idempotent Laws 5. Complement Laws...