object oriented programming in Python

Introduction

Programming को और ज्यादा structured, reusable और powerful बनाने के लिए Object Oriented Programming (OOP) का उपयोग किया जाता है।

OOP एक ऐसा programming approach है जिसमें हम real-world objects को program में represent करते हैं।

इसकी मदद से बड़े programs को आसानी से manage किया जा सकता है और code को reusable बनाया जा सकता है।

यह concept Python को basic level से advanced level तक ले जाता है।

इस Section में आप सीखेंगे

  • Classes
  • Objects
  • Methods
  • Basic OOP Concepts

OOP क्या होता है

Object Oriented Programming एक ऐसा तरीका है जिसमें program को objects के रूप में organize किया जाता है।

हर object के पास:

  • properties (data)
  • behavior (functions)

होते हैं।

Real-life समझ

जैसे:

  • Car → object
  • Color, Speed → properties
  • Start, Stop → methods

इसी तरह programming में भी objects बनाए जाते हैं।

OOP के फायदे

  • Code reuse होता है
  • Program structured बनता है
  • Maintenance आसान होती है
  • Real-world problems को आसानी से solve किया जा सकता है

OOP के मुख्य भाग

  1. Class
  2. Object
  3. Method
  4. Basic Concepts (Inheritance, Polymorphism, etc.)

अब हम इन सभी topics को एक-एक करके detail में समझेंगे।

1. Classes

Definition

Class एक blueprint या template होता है, जिससे objects बनाए जाते हैं।

Syntax

class ClassName:
pass

Example

class Student:
name = "Rahul"

2. Objects

Definition

Object class का instance होता है।

Example

class Student:
name = "Rahul"s1 = Student()
print(s1.name)

3. Methods

Definition

Method class के अंदर define किया गया function होता है।

Example

class Student:
def greet(self):
print("Hello Student")s1 = Student()
s1.greet()

self keyword

  • self object को represent करता है
  • हर method में पहला parameter होता है

Real-life Example: Student class

class Student:
def __init__(self, name):
self.name = name def show(self):
print("Name:", self.name)s1 = Student("Amit")
s1.show()

Basic OOP Concepts

1. Encapsulation

Data और methods को एक class में bind करना

2. Inheritance

एक class दूसरे class की properties use कर सकती है

3. Polymorphism

एक function कई forms में काम कर सकता है

4. Abstraction

Complex चीजों को hide करके simple interface देना

Common mistakes

  1. self keyword भूल जाना
  2. class और object में confusion
  3. method call गलत करना

Mini Program

class Car:
def start(self):
print("Car started")c1 = Car()
c1.start()

Summary

Object Oriented Programming Python का advanced concept है,
जो program को structured और reusable बनाता है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top