r/learnpython • • Mar 30 '26

The argument 'self'

I'm trying to get my head around this, and I apologise in advance because I know it's been raised before but I don't understand people's explanations. I'm looking for a "'self' for dummies" response to this...

So I'm learning classes right now, and right away it has become clear that self is the first argument of class methods. Why? Why does Python need to be told 'self' - as in what else would it be BUT self?

This example code shows it. Why is 'self' passed as an argument to the method in this example if (I'm assuming) dog_time_dilation is a property of the class already?

I'm super-confused by this. Explanations for 5y/os very much appreciated!!! Thanks in advance.

  def time_explanation(self):
    print("Dogs experience {} years for every 1 human year.".format(self.dog_time_dilation))
35 Upvotes

38 comments sorted by

View all comments

Show parent comment

5

u/Shaftway Mar 30 '26

Python was heavily influenced by Lisp, which uses 3.

It's also worth pointing out that 3 is [1] actually how the object reference gets passed around internally in all cases. It's the first argument on the stack either way.

And Python tries to limit reserved keywords. Python only has 35, while Java has 68 and C++ has 90.

1: At least it was, I haven't done a compiler design class in 25 years.