"Self" Argument

Here in this lesson i can’t understand why we have to use “self” argument and what does it refer to.
What does actually this mean ?
Ekran görüntüsü 2020-10-30 170555
How can self argument have attribute here ?
Here why i have to use self for example ?

Given self is the current instance/object of a class, Python passes it implicitly when we call a method on a instance/object

class variable (like dog_time_dilation) are also implicitly bound to self.

Instance variable have to explicitly bound:

class Example:
   def __init__(self, hello):
       self.hello = hello

   def print_instance_variable(self):

example = Example('hello world')

we can also call a method on the class itself, then we do have to provide argument for self:


In this example, we explicitly “bind” self parameter to example argument.

1 Like

So that means, self actually refers to class. For example, for using objects in functions we are using self argument with attribute(object’s name) to call it in functions.

No. Dog is the class. pip_pitbull is the instance/object. Which self refers the instance/object. Not the class

Classes have methods (like time_explanation and area). I wouldn’t name them functions, that is confusing, this is a function:

def myFunc():
   print("I am a function")
1 Like