class heritage in python code 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
class Robot:
def __init__(self, name):
self.name = name
def say_hi(self):
print("Hi, I am " + self.name)
class PhysicianRobot(Robot):
def say_hi(self):
print("Everything will be okay! ")
print(self.name + " takes care of you!")
y = PhysicianRobot("James")
y.say_hi()