The self
variable within our class represents the instance of the class. For example, if we created a Labrador instance of the Dog class and called labrador.bark()
, the self
variable in bark()
would refer to that labrador
object. Using self
we can assign attributes to the class. e.g name, breed
. We can also change the attribute values.
The self parameter is passed to the methods implicitly by Python when we call a method. Hence when we call change_name()
we dont have to pass an added variable for self
.