Asked • 03/29/19

What is the purpose of self?

What is the purpose of the `self` word in Python? I understand it refers to the specific object created from that class, but I can't see why it explicitly needs to be added to every function as a parameter. To illustrate, in Ruby I can do this: class myClass def myFunc(name) @name = name end endWhich I understand, quite easily. However in Python I need to include `self`: class myClass: def myFunc(self, name): self.name = nameCan anyone talk me through this? It is not something I've come across in my (admittedly limited) experience.

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.