object orientation – Use the self-method in Python

If you want to create a method, you need self. The object itself will be passed as part of the arguments of the method. He therefore needs a parameter to receive it. self.

If you only want one function, and in many cases, that's exactly what you really want, including this sample question, do not use the self, but also does not call as a method, that is, does not create an object to perform this function. In reality, neither create the class, after all classes exist to define objects and no object is defined in this code, just create functions.

It is therefore correct not to use the self but there is also no basis for creating a class to do something as simple and stateless to preserve, with no clear consistency as to its use. It produces the same result without difficulty:

def sum (n1, n2):
returns n1 + n2
subtract (n1, n2):
returns n1 - n2

print (add (5, 4))