python 'self' explained

Posted by richzilla on Stack Overflow See other posts from Stack Overflow or by richzilla
Published on 2010-04-25T20:22:28Z Indexed on 2010/04/25 20:23 UTC
Read the original article Hit count: 266

Filed under:
|
|

What is the purpose of the 'self' word in python. I understand it refers to the specific object created from that class, but i cant see why it explicitly needs to be added to very function as a parameter. To illustrate, in ruby, i could do this:

class myClass
    def myFunc(name)
        @name = name
    end
end

Which i understand, quite easily, However in python i need to include self:

class myClass:
    def myFunc(self, name):
        self.name = name

Can anyone talk me through this? Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about python

Related posts about self