Blog

Oops concept in python in hindi - Bharosewale

Posted By Naveen Singh on 11 May 2023

python-program
oops-concept-in-python-in-hindi

 

Python में Oops concept क्या हैं? (What is Oops concept in python?)

 

Python में,object oriented programming systems (OOPs) एक programming  प्रतिमान(paradigm)है जो की programming में objects एवम classes का उपयोग करता है। इसका aim

programming में inheritance, polymorphism, encapsulation आदि जैसी वास्तविक दुनिया(real world) की entities को implement करना है। OOPs का मुख्य concept data और उस पर

काम करने वाले functions को एक unit के रूप में बांधना है ताकि code का कोई भी अन्य भाग इस data पर न पहुंच सके।

 

Main Concepts of Object-Oriented Programming Systems(OOPs)

 

Object oriented programming के कुछ main concept होते हैं जिनका उपयोग हम आगे एक-एक करके देखेगे| ये basically 6 प्रकार के होते हैं -

• Class

• Objects

• Polymorphism

• Encapsulation

• Inheritance

• Data Abstraction

 

Class-: 

 

object oriented programming में class objects का collection होता है। एक class में blueprint या prototype होता है जिससे objects बनाए जा रहे हैं। यह एक logical entity है जिसमें कुछ

विशेषताएँ(attributes) और method होते हैं।

 

Python में class को create कैसे करे?(How to create class in python?)

Python में हम class को class keyword के through create करते है।

 

Syntax-:

class Class_Name:

   Statement

 

Example-:

class my_class:

   print("my first class")

 

Output-:

my first class

 

Object-:

 

object एक तरह की entity है जिसके अन्दर state और behavior होता है। यह वास्तविक दुनिया की कोई भी प्रकार की वस्तु हो सकती है जैसे keyboard, mouse, chair, pen आदि।

Python में सब कुछ एक प्रकार की वस्तु ही है, और लगभग हर चीज में attributes और methods  हैं|

 

Python में object create कैसे करें?( How to create object in python?)

 

class First_Class:

  a = 10

obj = First_Class()

print(obj.a)

 

Output-:

10    

 

Polymorphism-:

 

polymorphism शब्द का अर्थ है many forms programming में, polymorphism का मतलब एक ही नाम का function (लेकिन अलग-अलग तरीके) का उपयोग विभिन्न प्रकारों के लिए किया जा

सकता है। मुख्य अंतर data type और function में उपयोग किए जाने वाले argument की संख्या होती है।

 

Encapsulation-:

 

Encapsulation object oriented programming  (OOP) के अन्दर fundamental concept में से ही एक है। यह data को wrap करके विचार और एक unit के भीतर data पर काम करने वाली

method का वर्णन करता है।

 

Inheritance -:

 

Inheritance  में एक class से दूसरे class के properties को inherit करने की क्षमता है। वह class जो properties को प्राप्त करता है उसे derived class या child class कहा जाता है और जिस

class से properties को प्राप्त किया जा रहा है उसे base class या parent class कहा जाता है।

 

Data Abstraction-:

 

यह user से unnecessary code details को hide करता है। इसके अलावा, जब हम अपने implemented code के sensitive part को show नहीं करने देना चाहते हैं, तो वहां पर हम data

abstraction का use करते हैं|


 

Python में self क्या है? (What are self in python?)

 

self एक प्रकार का keyword होता है। जो की instance class को represent करता है। "self" का उपयोग करके हम python में class के methods और attributes को access कर सकते हैं। यह

दिए गए arguments के साथ attributes को जोड़ देता है।

 

Example-:

class Number:

  def _init_(myobject, name, age):

    myobject.name = name

    myobject.age = age

  def function(new):

    print("Hello my name is " + new.name)

obj = Number("Harrison", 40)

obj.function()

 

Output-:

Hello my name is Harrison


 

Python में _init_() function क्या है?( What is _init_ function in python?)

 

Python में _init_() function एक तरह का constructor होता है जिसका use हम objects की state को initialize करने के लिए उपयोग किया जाता है। जब class का object बनाया जाता है, तो

constructor का काम class के data members को initialize करना (value को assign करना) होता है। methods की तरह, एक constructor में भी statements (i.e instruction) का एक

संग्रह(collection) होता है, जिसे objects निर्माण के समय execute किया जाता है। जैसे ही किसी class के object को तत्काल चलाया जाता है। यह method किसी भी initialization को करने के लिए

उपयोगी होता है जिसे आप अपने objects के साथ करना चाहते हैं।

 

Example-:

class Myclass:

    # init method or constructor

    def _init_(self, name):

        self.name = name

    # Sample Method

    def func(self):

        print('Hello, this is', self.name)

obj = Myclass('Naveen')

obj.func()

 

Output-:

Hello, this is Naveen


 

Comments