OOP, Object Oriented Programing का ही sort form है। PHP, Java, JavaScript और C ++ की तरह ही Python भी OOP Concept को support करती है। और जैसा कि आप पहले भी पढ़ चुके हैं कि Python में almost सबकुछ Object ही है।


OOP (Object Oriented Programing) Classes और Objects पर based एक Programming Paradigm / Approach है। Simple भाषा में कहें तो OOP (Object Oriented Programing) Real World Entity/Object को Programming में represent करने का method / way है।


Real World Entity को ही Programing में Class / Object द्वारा represent किया जाता है। Entity की कुछ Properties या Behavior होता है जिसे Programing में Class variables & methods से represent किया जाता है।

Python class

Class किसी Object के लिए एक Blueprint होता है। जैसे Real World Entity की कुछ Properties या Behavior होता है जिसे Programing में Class variables & methods से represent किया जाता है।


Python में class define करने के लिए predefined keyword class का use किया जाता है , और उसके बाद class का name define किया जाता है।

Python Class Syntax

class className :
   #class variables.
   #class methods.

Python Initiating Class Object

अब हम देखेंगे की कैसे class का Object बनाते हैं। Python में Class name के साथ parenthesis () का use किसी class का Object बनाते है।
See Example -

myObj = myClass()

Python class Example

Copy Fullscreen Close Fullscreen Run
class myClass :
  pass


myobj = myClass()
print('type is :', type(myobj))
print(myobj)
Output
C:\Users\Rahulkumar\Desktop\python>python class_ex.py
type is : <class '__main__.myClass'>
<__main__.myClass object at 0x01CDA268>

तो कुछ इस तरह से हम Python में class बनाते हैं।

Python class : Important

1. जैसा कि आप पहले भी पढ़ चुके हैं कि Python case sensitive language इसलिए class name define करते ध्यान रहे कि myclass और MyClass दोनों अलग अलग हैं।

2. Class name किसी alphabet या underscore (जैसे : _name , name) से start होते हैं। classes के name numbers से start नहीं हो सकते हैं।
For Example -

class 1myClass :
  pass

or

class @myClass :
  pass

3. Class Name में alphabets (A - z) , numbers (0 - 9) , underscore ( _ ) हो सकते हैं। numbers को आप class name के बीच में या last में use कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers