0 votes

1 Answer

0 votes
by

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.

Example

                                                    

class Dog:

    def __init__(self, breed):

        self.breed = breed

    def bark(self):

        print(f'{self.breed} is continuously barking.')

d = Dog('German Shepherd')

d.bark()

Output

German Shepherd is continuously barking.

...