__init__ method of a class is a function that automatically gets called when an instance of the class is created. It serves the special purpose of performing whatever tasks that the programmer deems necessary for the creation of that instance. Usually, but not always, this includes the setting up of instance variables.
The first parameter of a method always refers to the current instance of the class to which it belongs. Conventionally, this parameter is named
self, so it is best to use that name. Any parameters that follow that first one are local variables of the method to which they belong. In order for information that is passed to the
__init__ method as arguments to be available for later use, that information must be stored or used in some manner that persists after the
__init__ method terminates. Quite often this entails the creation of instance variables. That is why we have statements such as this one:
self.name = name
The above establishes
name as an instance variable. This variable will persist and be accessible even after the
__init__ method terminates. Without such a statement,
name would be merely a local variable that would not be recognized outside the
Functions that are not methods serve a wide variety of purposes, and that is why most of them do not do what is described above.