inheritance python example
Example 1: inheritance in python
class Parent:
BloodGroup = 'A'
Gender = 'Male'
Hobby = 'Chess'
class Child(Parent):
BloodGroup = 'A+'
Gender = 'Female
def print_data():
print(BloodGroup, Gender, Hobby)
child1 = Child()
child1.print_data()
Example 2: inheritance in python 3 example
<__main__.Robot object at 0x7fd0080b3ba8> <class '__main__.Robot'>
<__main__.PhysicianRobot object at 0x7fd0080b3b70> <class '__main__.PhysicianRobot'>
Hi, I am James
Example 3: how to inherit a class in python
class Bird():
def eat(self):
print ("eating")
class Sparrow(Bird):
def sound(self):
print ("ChiChi!")
birdobj = Sparrow()
birdobj.eat()
birdobj.sound()