+ 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()

20th Jan 2022, 11:50 AM
Abhishek
Abhishek - avatar
14 ответов
+ 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
20th Jan 2022, 1:28 PM
Vitaly Sokol
Vitaly Sokol - avatar
+ 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
20th Jan 2022, 11:54 AM
Lisa
Lisa - avatar
+ 3
try changing the order of parenting for c class c(p3,p2,p1): and you will see the difference.
21st Jan 2022, 1:01 AM
Bob_Li
Bob_Li - avatar
+ 1
Please explain me
20th Jan 2022, 11:59 AM
Abhishek
Abhishek - avatar
0
I don't understand
20th Jan 2022, 11:58 AM
Abhishek
Abhishek - avatar
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.
20th Jan 2022, 12:03 PM
Lisa
Lisa - avatar
0
I am looking but this question precedence how it's work
20th Jan 2022, 12:10 PM
Abhishek
Abhishek - avatar
0
c inherits 1. from p1
20th Jan 2022, 12:11 PM
Lisa
Lisa - avatar
0
I also mention super.init so why
20th Jan 2022, 12:24 PM
Abhishek
Abhishek - avatar
0
That how c inherits the constructor
20th Jan 2022, 12:26 PM
Lisa
Lisa - avatar
0
Can u explain the whole program so I can understand better
20th Jan 2022, 12:28 PM
Abhishek
Abhishek - avatar
0
Because i learn Today about it
20th Jan 2022, 12:28 PM
Abhishek
Abhishek - avatar
0
Hi
22nd Jan 2022, 1:59 AM
Tv 123
Tv 123 - avatar
0
scb
22nd Jan 2022, 9:54 AM
Elbek Abdishukirov
Elbek Abdishukirov - avatar