OneCompiler

unable to perform addition inside the class in Python

def add (a, b):
   print (a+b)

I have this function inside a class and when I call it using object I am getting an error

1 Answer

5 years ago by

Inside the class functions the first argument must be self

def add(self, a, b):
   print(self.a + self.b)

5 years ago by Divya