the creation of an instance is carried out in two steps using the special method _new_ ()which creates new instanceand _init_ ()which initializes it for examplethe operation circle( performs these stepsc circle _new_ (circle if isinstance( ,circle)circle _init_ ( , the _new_ (method of class is something that is rarely defined by user code if it is definedit is typically written with the prototype _new_ (cls*args**kwargswhere args and kwargs are the same arguments that will be passed to _init_ ( _new_ (is always class method that receives the class object as the first parameter although _new_ (creates an instanceit does not automatically call _init_ (if you see _new_ (defined in classit usually means the class is doing one of two things firstthe class might be inheriting from base class whose instances are immutable this is common if defining objects that inherit from an immutable built-in type such as an integerstringor tuple because _new_ (is the only method that executes prior to the instance being created and is the only place where the value could be modified (in _init_ ()it would be too latefor exampleclass upperstr(str)def _new_ (cls,value="")return str _new_ (clsvalue upper() upperstr("hello"value is "hellothe other major use of _new_ (is when defining metaclasses this is described at the end of this once createdinstances are managed by reference counting if the reference count reaches zerothe instance is immediately destroyed when the instance is about to be destroyedthe interpreter first looks for _del_ (method associated with the object and calls it in practiceit' rarely necessary for class to define _del_ (method the only exception is when the destruction of an object requires cleanup action such as closing fileshutting down network connectionor releasing other system resources even in these casesit' dangerous to rely on _del_ (for clean shutdown because there' no guarantee that this method will be called when the interpreter exits better approach may be to define method such as close(that program can use to explicitly perform shutdown occasionallya program will use the del statement to delete reference to an object if this causes the reference count of the object to reach zerothe _del_ (method is called howeverin generalthe del statement doesn' directly call _del_ ( subtle danger involving object destruction is that instances for which _del_ (is defined cannot be collected by python' cyclic garbage collector (which is strong reason not to define _del_ unless you need toprogrammers coming from languages without automatic garbage collection ( ++should take care not to adopt programming style where _del_ (is unnecessarily defined although it is rare to break the garbage collector by defining _del_ ()there are certain types of programming patternsespecially those involving parent-child relationships or graphswhere this lib fl ff