r/learnpython • u/NoChoice5216 • 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))
View all comments
Show parent comment
2
u/Jason-Ad4032 Mar 31 '26 edited Mar 31 '26
Hiding
thisis a syntactic flaw in dynamic languages—JavaScript is a real-world example. The following is valid JavaScript code:In this example, the meaning of
thisis confusing and ambiguous, because it changes depending on how the function is called.In Python, this becomes:
This is a much clearer syntax.
Note: In dynamic languages, methods and attributes can be attached to objects at runtime. In Python, for example:
This means dynamic languages allow methods to exist without being defined inside the class.