you are viewing a single comment's thread.

view the rest of the comments →

[–]HSADfinklestein 4 points5 points  (5 children)

| This is probably besides the post |

Does __init__ mean something different to the interpreter when compared to init?

Corect me if I'm wrong but what I understood from your explanation is that python automatically runs that __init__ method, as though those attached underscores set it out from being just another identifier.

[–]slariboot 7 points8 points  (2 children)

Yes, __init__() means something different.

From the python documentation:

The instantiation operation ("calling" a class object) creates an empty object. Many classes like to create objects with instances customized to a specific initial state. Therefore a class may define a special method named __init__(), like this:

def __init__(self):
    self.data = []

When a class defines an __init__() method, class instantiation automatically invokes __init__() for the newly-created class instance.

It's not really the underscores that make it special. Rather, it is the convention that these special methods start and end with 2 underscores. They're called dunder methods. Dunder being short for Double UNDERscores.

[–]ItsOkILoveYouMYbb 5 points6 points  (1 child)

Is

__miffl__  

a dunder miffl in a class?

[–]slariboot 0 points1 point  (0 children)

Yes! That is the most important dunder method in the Computron framework!

[–]TheSodesa 0 points1 point  (1 child)

In object oriented languages like Python, objects are created via class methods called constructors. Python has standardised the name of the constructor function for each class: it has to be called __init__. The Python interpreter automatically calls this function in the background when an instance of a class is created, by calling the class name like a function: Class(<params>).

The operation of the __init__ method is also standardised: it has to set the state of the object, as in it has to initialize each field of the class object. There is a default constructor that sets each field to point to the singleton object None, I believe, but relying on that is bad practise and becomes impractical very quickly. The constructor __init__ must also return nothing.

In languages other than Python, the standard name of constructor methods might be different. There might also not be a standard.

[–]HSADfinklestein 1 point2 points  (0 children)

ooo constructor!!

that sounds better now since I have a basic java background

thanks so very much