python 'self' explained
- by richzilla
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.