0

what is super function ?

class A: def spam(self): print(1) class B(A): def spam(self): print(2) super().spam() B().spam() Since class A & class B have same method, it must overwritten and print 2 but instead of this it print 2 and 1 why?

16th Nov 2019, 9:13 AM
#ArizmaAltair PATHAN
#ArizmaAltair PATHAN - avatar
4 Answers
+ 1
~ swim ~ you didn't ans my full que..I also ask that since class A & class B have same method , it must overwritten and print 2 but instead of this it print 2 and 1..that part is not clear to me .can you give me proper explanation?..since I am not clearly understand from the course explanation !!!
16th Nov 2019, 10:17 AM
#ArizmaAltair PATHAN
#ArizmaAltair PATHAN - avatar
0
From the definition of the method spam(self) in class B (which inherits from A), B().spam() will first print 2, then call the method spam from the superclass A, which prints 1.
17th Nov 2019, 12:11 PM
Njeri
Njeri - avatar