Possible Duplicate:
Why do you need explicitly have the “self” argument into a Python method?
Why do I have to add this self parameter
def function(self):
Possible Duplicate:
Why do you need explicitly have the “self” argument into a Python method?
Why do I have to add this self parameter
def function(self):
Because when you define a method inside a class, it automatically creates a descriptor that passes the object instance as the first parameter. If you want to avoid this, use the @staticmethod decorator, or just define your functions outside the class.
As for why the language is designed this way, it wouldn't make sense to do it otherwise in a language without explicit variable creation. If you do a=2, how do you know whether it should be a local or an instance variable? Also, passing it explicitly is just a more elegant design in general.