+ 1

Plz explain these lines to me

The first stage of the life-cycle of an object is the definition of the class to which it belongs. The next stage is the instantiation of an instance, when __init__ is called. Memory is allocated to store the instance. Just before this occurs, the __new__ method of the class is called. This is usually overridden only in special cases.

17th Jul 2018, 11:57 AM
adarsh pandey
adarsh pandey - avatar
3 odpowiedzi
0
I assume this is Ruby. To have an object, first define its class. You can’t have tom without having Person. This step involves writing code defining what a Person is and can do. Then you create an object by doing tom = Person.new(“tom”) Now what happens is behind the scenes. The new method creates the object (sets aside memory for it in the computer), then automatically calls the init method on the newly created object before you’ve done anything with it. In this case, init tells tom that its name is “tom” (tom.name == “tom”). Now the object tom is good and ready to go.
20th Jul 2018, 4:34 PM
Alexander
Alexander - avatar
0
it's python
20th Jul 2018, 5:13 PM
adarsh pandey
adarsh pandey - avatar
0
Okay sorry about that, but I believe the answer still holds other than the syntax
22nd Jul 2018, 5:08 AM
Alexander
Alexander - avatar