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()
7 Réponses
+ 8
2
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 ??
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
0
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
- 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
- 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.