0

Isn't "__new__" the constructor in a python class?

According to the python 3 tutorials "__init__" is the constructor method but it isnt. "__init__" is called after an object is instanciated. The constructor is "__new__"

21st Apr 2020, 5:49 PM
Hussaini Magaji
Hussaini Magaji - avatar
1 Odpowiedź
0
Yes, you're correct. __new__() creates the instantiated object and then calls __init__(), which is often referred to as being the constructor due to this is where the objects 'self' has its members initialized. The __new__ method is the actual object constructor 'self', but __init__ is the instantiated 'self' constructor. https://docs.python.org/3/reference/datamodel.html#object.__new__ https://docs.python.org/3/reference/datamodel.html#object.__init__
21st Apr 2020, 6:53 PM
ChaoticDawg
ChaoticDawg - avatar