Just to make sure if I understood the Lesson 74.1 correctly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Just to make sure if I understood the Lesson 74.1 correctly

Is super function like if there are the same methods in superclass and subclass, super function calls superclass' method?

5th May 2022, 2:08 PM
Noel K
1 Answer
+ 1
If you have a subclass, the __init__ method should include a call to the super classes __init__ method. class A: def __init__(self): self.val = 5 class B(A): def __init__(self): super().__init__() Now if you create an instance of class B, it will have the val attribute that has the value 5. This is only set because of the call to the super classes __init__ method INSIDE of the subclass __init__ method.
5th May 2022, 4:20 PM
Slick
Slick - avatar