Python self method

 

self method

The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class.

It must be provided as the extra parameter inside the method definition. 

 

Example:

class Details:
    name = "Maxon"
    age = 26

    def desc(self):
        print("My name is", self.name, "and I'm", self.age, "years old.")

obj1 = Details()
obj1.desc()

 

Output:

My name is Maxon and I'm 26 years old.