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.

BY Best Interview Question ON 31 May 2020


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.