Can anyone tell me how does Python interpreter or PVM manage memories for the following code?
class_purpose = "template"
self.a = 0.0
self.b = 0.0
return self.a, self.b
print "This is class A"
a = A()
Everything in your example is simply an object. All objects go on the heap.
The class object is created at runtime and has a mapping from attribute name to objects, where all names you defined in the class body are simply attributes. The majority of those objects implement the descriptor protocol (the exception being the
class_purpose attribute). The function objects that form the majority of the attributes are also created at runtime; all the compiler produces are code objects which store bytecode, some constants (anything immutable created by the code, including more code objects for nested scopes).
See the datamodel reference documentation for more details on how these objects relate to one another.
The vast majority of Python developers don't have to worry about memory management. If you develop against the Python C API, you may want to read up on the Memory Management section, which does state:
It is important to understand that the management of the Python heap is performed by the interpreter itself and that the user has no control over it, even if she regularly manipulates object pointers to memory blocks inside that heap. The allocation of heap space for Python objects and other internal buffers is performed on demand by the Python memory manager through the Python/C API functions listed in this document.