inheritance - Function "super". | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

inheritance - Function "super".

class A: def spam(self): print(1) class B(A): def spam(self): print(2) super().spam() B().spam() Can anyone please explain this code ?????? Thanks in advance.

18th Feb 2019, 1:24 PM
Shriram Kumar Sethi
Shriram Kumar Sethi - avatar
1 Answer
+ 1
B inherits from A. super().spam() calls the method of the 'mommy' of B. So when you call B's spam, it will print 2, then call A's spam which will print 1.
18th Feb 2019, 1:41 PM
HonFu
HonFu - avatar