I tried running these few lines of Python code involving super & MRO.
The line class Child(Add, Sub, Mul, Sqroot, Div):
is deciding the First line of the output i.e. currently Inside add class
.
Please help me with the concept, because if I changed that line to class Child(Sqroot, Add, Sub, Mul, Div):
, the first line of the output changed to Inside sqroot class
class Sqroot(object):
def __init__(self):
print 'Inside sqroot class'
def sqroot(self, num):
print 'The square root of the number is ',num**0.5
class Add(object):
def __init__(self):
print 'Inside add class'
def add(self, num1, num2):
print 'The sum is :', num1+num2
class Sub(object):
def __init__(self):
print 'Inside subtraction class'
def sub(self, num1, num2):
print 'The subtraction is :', num1-num2
class Mul(object):
def __init__(self):
print 'Inside multiplication class'
def mul(self, num1, num2):
print 'The multiplication is :', num1*num2
class Div(object):
def __init__(self):
print 'Inside division class'
def div(self, num1, num2):
print 'The division is :', num1/num2
class Child(Add, Sub, Mul,Sqroot, Div):
def __init__(self):
super(Child, self).__init__()
ob = Child()
ob.sqroot(9)
ob.add(6,4)
ob.sub(3,5)
ob.mul(6,4)
ob.div(6,4)
OUTPUT:-
Inside add class
The square root of the number is 3.0
The sum is : 10
The subtraction is : -2
The multiplication is : 24
The division is : 1