The difference between the python and __new__ method __inti__

This object-oriented from the Python instantiation process Speaking

Then after the class name (), to open up a memory space, and then call the __init__ the memory address space of the transfer function as a parameter to the internal self, parameters, and properties are associated with self-related and self all up, execution __init__ , self will automatically return to the calling out

 

class A:
     DEF   __new__ is (CLS, args *, ** kwargs): 
        O . = Object __new__ is (CLS)
         Print ( ' performs a new new ' , O)
         return O
     DEF  the __init__ (Self):
         Print ( ' performs the init ' , Self ) 
a () 

# instantiation 
# create a space object, a pointer can point type -> __new__ 
# call init -> __init__ 

execution results
The implementation of the new new < __main__ II.A, Object AT 0x0000000001D927F0> 
execute the init < __main__ II.A, Object AT 0x0000000001D927F0>

So __new__ is performed before __init__,

__new__ is to create an object before the object is created, and returns the object to the init. When you create a class object call

__init__ after the object is created, an object is initialized. Call at instantiation

 

 

Guess you like

Origin www.cnblogs.com/well-666/p/11913642.html