Facebook Pixelself method | Python Tutorial | CodeWithHarry

self method

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

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

Example:

class Details:
    name = "Simran"
    age = 20
 
    def desc(self):
        print("My name is", self.name, "and I'm", self.age, "years old.")
 
obj1 = Details()
obj1.desc()

Output:

My name is Simran and I'm 20 years old.