Why p1 output come | Sololearn: Learn to code for FREE!


Why p1 output come

class p1: def __init__(self): print("p1") class p2: def __init__(self): print("p2") class p3: def __init__(self): print("p3") class c(p1,p2,p3): def __init__(self): super().__init__() a=c()

1/20/2022 11:50:43 AM

abhishek bairwa

14 Answers

New Answer


In Python, the method resolution order (MRO) is from bottom to top and left to right. This means that, first, the method is searched in the class of the object. If it’s not found, it is searched in the immediate super class. In the case of multiple super classes, it is searched left to right, in the order by which was declared. for eg.: https://code.sololearn.com/caRd55t9fbHC/?ref=app


Because c inherits from p1, p2, p3 and p1 has precedence to p2, p3 isn't it the same question here? https://www.sololearn.com/Discuss/2966106/?ref=app


try changing the order of parenting for c class c(p3,p2,p1): and you will see the difference.


Please explain me


I don't understand


I did explain in my initial comment. OOP is covered in the Python Core course on sololearn. You may want to have a look at the course.


I am looking but this question precedence how it's work


c inherits 1. from p1


I also mention super.init so why


That how c inherits the constructor


Can u explain the whole program so I can understand better


Because i learn Today about it