Why Result is 2 not 1 ? a() method already defined in both A&B . How to call the super class method from child class in this par | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why Result is 2 not 1 ? a() method already defined in both A&B . How to call the super class method from child class in this par

class A: def a(self): print(1) class B(A): def a(self): print(2) class C(B): def c(self): print(3) c = C() c.a()

8th Mar 2017, 9:51 AM
Muhamed Ziedan
Muhamed Ziedan - avatar
7 Answers
+ 8
2
30th Mar 2020, 2:13 AM
natalie hernandez
natalie hernandez - avatar
0
pretty clear thanks lord 👌. Result as following: >>> 1 None # why None ? def a(self): # what is the need of a() in C super(B,self).a() # this call a() in A , Why ?? super().a() # but this call a() in B , Why ??
8th Mar 2017, 11:17 AM
Muhamed Ziedan
Muhamed Ziedan - avatar
0
What is the result of this code? class A: def a(self): print(1) class B(A): def a(self): print(2) class C(B): def c(self): print(3) c = C() c.a() output:2
28th Apr 2020, 9:40 AM
makhan Kumbhkar
makhan Kumbhkar - avatar
0
5th Jun 2020, 4:06 PM
Aythiga C
Aythiga C - avatar
0
What is the result of this code? class A: def a(self): print(1) class B(A): def a(self): print(2) class C(B): def c(self): print(3) c = C() c.a() Ans: 2
6th Dec 2020, 10:13 AM
IRFAN KHAN
IRFAN KHAN - avatar
- 1
What is the result of this code? class A: def method(self): print(1) class B(A): def method(self): print(2) B().method() output:2
28th Apr 2020, 9:40 AM
makhan Kumbhkar
makhan Kumbhkar - avatar
- 2
Thanks ,Do I really need to define a() method in C to be able to call the super class A. when I tried super(B,self).a() without def a() : in C >>> 2 , still refering to the Base class not the Super.
8th Mar 2017, 4:16 PM
Muhamed Ziedan
Muhamed Ziedan - avatar