__del__() "Destructor" Method : Instance : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Instance »

 

__del__() "Destructor" Method


class C():              
    def __init__(self):  
         print 'initialized'
    def __del__(self):   
         print 'deleted'

c1 = C()               
c2 = c1                
c3 = c1                
print id(c1), id(c2), id(c3
del c1                       
del c2                       
del c3                       


  
class InstCt(object):
    count = 0                

    def __init__(self):      
         InstCt.count += 1

    def __del__(self):       
         InstCt.count -= 1

    def howMany(self):       
        return InstCt.count

a = InstCt()
b = InstCt()
print b.howMany()
print a.howMany()
del b
print a.howMany()
del a
InstCt.count



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Instance