What is the purpose of the word ‘self’?

What is the purpose of the self word in Python? I understand it refers to the specific object instance created from that class. But why does it explicitly need to be added to every function as a parameter? To illustrate, in Ruby I can do this:

class MyClass
    def func(name)
        @name = name
    end
end

However, in Python I need to include self:

class MyClass:
    def func(self, name):
        self.name = name

2
26

Leave a Comment