+ 3

Is python init a constructor?

Construction of a Python object is simply allocation of a new instance followed by initialization of said instance. Personally, I find " __init__ is not a constructor" to be pretty fine hair-splitting. ... A C++ constructor is called when a new object is requested.

26th Feb 2018, 5:37 PM
Azeem Ghafoor
Azeem Ghafoor - avatar
4 ответов
+ 6
@Azeem I am with you how said that?
26th Feb 2018, 6:52 PM
Oma Falk
Oma Falk - avatar
+ 2
although we use __init__ almost the same sense as c++/java constructor while programming ( to create members of a new class instance ), it is not really the same in how it works because Python is dynamic language while C++/Java are static. there is no scientific definition of what a constructor is. if you don't have init in your class your code will work and there is no call for a constructor implicitly like C++/Java.
26th Feb 2018, 8:04 PM
Azeem Ghafoor
Azeem Ghafoor - avatar
+ 1
__new__ is the constructor, but it is not usually used in classical programming. __init__, however, is the initialiser, it populates the instance with the given arguments and then you have a working instance
26th Feb 2018, 10:10 PM
Amaras A
Amaras A - avatar
0
They’re constrictors, not constructors. They strangle their prey to death. Must have been a auto correct. 😂 But to be honest, I’m not sure.
26th Feb 2018, 6:10 PM
Jax
Jax - avatar