Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Python Inheritance ( python class part 👉 21 in Hindi)

 

Python Inheritance

Inheritance का उपयोग कर parent class की सभी properties(data member व member function) को child class में उपयोग किया जाता है।

Parent class जो inherit की जाती है उस class को कहते है और child class वो class है जो दूसरे क्लास को inherit करती है।

Example

class ParentClass:        # parent class name
   price = 100
   def __init__(self):
      print "Hello parent constructor"

   def myParentMethod(self):
      print 'parent method'

   def setAmount(self, amt):
      Parent.price = amt

   def getAmount(self):
      print "price is :", Parent.price

class ChildClass(Parent): # child class name
   def __init__(self):
      print "Hello child constructor"

   def myChildMethod(self):
      print 'Inside child method'

c = ChildClass()       # Create object of child
c.myChildMethod()      # calls child method
c.myParentMethod()     # calls parent's method
c.setAmount(1200)      # again parent's method call to set amount
c.getAmount()          # again parent's method call to get amount

Agar kuch samajh nahi aaya to comments zaroor kare tutorial ke liye... And Jude rehiye hamare blog se and sand kare apne dosto me .... 


Next class part 👉 22  par jay


एक टिप्पणी भेजें

0 टिप्पणियाँ