In Python, a self variable is used for binding the instance within the class to the instance inside the method. In this, to access the instance variables and methods, we have to explicitly declare it as the first method argument.



class Dog:
    def __init__(self, breed):
        self.breed = breed
    def bark(self):
        print(f'{self.breed} is continuously barking.')
d = Dog('German Shepherd')

German Shepherd is continuously barking.

Suggest An Answer

No suggestions Available!