0

What is main __init__? please

10th Aug 2016, 7:56 AM
ADEL
ADEL - avatar
1 Answer
+ 1
It is the constructor method. A method is a function associated to an object. This method is used to set the initial value of some attributes referred to the current instance of the class. For example if you create a class A with some attributes, like A.one, A.two, the code: def __init__(self,a,b): self.one = a self.two = b lets you to set the initial value for the attributes on the value that you want. The declaration a = A(8,9) sets a.one to 8 and a.two to 9. The self parameter is a pointer, and refers to the current object. The __init__ method is not required, but is generally useful for classes.
10th Aug 2016, 6:21 PM
Salvatore Correnti
Salvatore Correnti - avatar