__init__ The __init__ method is similar to constructors in C++ and Java . Constructors are used to initialize the object’s state. The task of constructors is to initialize(assign values) to the data members of the class when an object of class is created. … It is run as soon as an object of a class is instantiated.
What is def __ init __ python?
__init__ : “__init__” is a reseved method in python classes. It is known as a constructor in object oriented concepts. This method called when an object is created from the class and it allow the class to initialize the attributes of a class.
Why do I need __ init __?
The __init__.py files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as string , unintentionally hiding valid modules that occur later on the module search path.