I am new to classes in python. I searched and went through so many articles on super()
method which creates so much of confusion.
Type - 1
class Square():
def __init__(self,side):
self.side = side
print("Its confusing")
super().__init__()
def area(self):
return self.side * self.side
c = Square()
print(c.area())
In Type - 1 , if I mention super().__init__()
what is the use of it? I don't understand why we use super().__init__()
in a newly created class which is not inherited from any other class. And I don't understand what it does here.
If we give it after assigning self.side = side
it runs properly and is executed.
Type - 2
class Square():
def __init__(self):
# self.side = side
# print("Its confusing")
super().__init__()
e = Square()
e()
If I just give only super().__init__()
inside __init__
it gives error.
TypeError: 'Square' object is not callable
My doubt is:
1.Can we use super().__init__()
in a newly created class? and It runs well without error.
2.Then why is Type - 2 throwing error if I put only super().__init__()
inside __init__
?
Can you please make it in simple words?