DEV Community

Discussion on: Python: __init__() is not the only constructor

 
rfletchr profile image
Rob Fletcher • Edited

what do you define as a "true" constructor?

take a look at C++ as an example. once you are in a constructor the classes memory has already been allocated, even uninitialised members have memory assigned to them. The constructor is customising the instance.

A c++ class with a zero constructor is like a python class with no init. you get a default instance.

Thread Thread
 
delta456 profile image
Swastik Baranwal

I changed the title again. Does it looks fine now?

Thread Thread
 
bradleygrant profile image
Bradley Grant

I thought you changed the title, it definitely wasn't what I remembered seeing.

I think it would be useful to understand exactly what internal functions are called every time a new instance is created, for instance __new__ and __init__, are there any others?

Thread Thread
 
delta456 profile image
Swastik Baranwal

There is also __del__ which is called but it is not needed to make because it de-allocates the object. I think it functions like a destructor.