Possible Duplicate:
Python ‘self’ explained
I have looked for some time but i still don’t understand self in python
def cut(self, cats, dogs):
self.cats = cats
self.dogs = dogs
print cats, dogs
cut(1,5)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
selfis just a local variable. You could name it anything you like, but the convention is to name itself. When a function is invoked as a method, i.e. on an actual object, Python will pass a reference to the object as the first argument. This is whatselfpoints to.obj.method(param)is actually just syntactic sugar forObjType.method(obj, param). So that’s where the parameter comes from.