0
Would you explain init and self here ?
2 odpowiedzi
+ 3
When you create an object, it calls __init__ method to initialize it. It is not really a constructor, since it doesn't create the object itself.
In a class, self refers to the object itself (not the class name but an instance of this class).
See classes as plans. You instanciate a new object following the plans.
I.e :
x = Person()
You create here a new object of type Person.
+ 2
`init` is the constructor function of `Person` class,
and `self` is the `Person` object itself.