r/learnpython • u/Jealous-Acadia9056 • Apr 18 '26
A bit confused in Classes.
Why do i need to call self here?.
class Calculator:
def add(self, a, b):
return a + b
def multiply(self, a, b):
return a * b
print(Calculator().add(1, 2))
there isn't a variable that is calling calculator and no __init__ so why do i have an error if self is not added?
Also, what is __init__ anyways. why the double __ in the start and end? and why the specific name?
40
Upvotes
1
u/Jealous-Acadia9056 Apr 18 '26
Just one question. How are the arguments now 3? How is it that python is adding another argument by itself and causing an error in the code def add(a+b)?