class inherit from parent class 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: inheritence in python
class A:
def feature1(self):
print('Feature 1 in process...')
def feature2(self):
print('Feature 2 in process...')
class B:
def feature3(self):
print('Feature 3 in process...')
def feature4(self):
print ('Feature 4 in process...')
a1 = A()
a1.feature1()
a1.feature2()
a2 = B()
a2.feature3()
a2.feature4()
class A:
def feature1(self):
print('Feature 1 in process...')
def feature2(self):
print('Feature 2 in process...')
class B(A):
def feature3(self):
print('Feature 3 in process...')
def feature4(self):
print ('Feature 4 in process...')
a1 = A()
a1.feature1()
a1.feature2()
a2 = B()
a2.feature3()
a2.feature4()