+ 2
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()
14 odpowiedzi
+ 10
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
+ 5
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
+ 3
try changing the order of parenting for c
class c(p3,p2,p1):
and you will see the difference.
+ 1
Please explain me
0
I don't understand
0
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.
0
I am looking but this question precedence how it's work
0
c inherits 1. from p1
0
I also mention super.init so why
0
That how c inherits the constructor
0
Can u explain the whole program so I can understand better
0
Because i learn Today about it
0
Hi
0
scb