QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12A-2015-B01A #6334

Question:

How is __init( ) __different from __del ( )__ ?

Answer:

__init__() is the class constructor or initialization method which is automatically invoked when we create a new instance of a class.
__del__() is a destructor which is automatically invoked when an object (instance) goes out of scope.
For Example:

class Sample:
    def __init__(self):
        self.data = 79
        print('Data:',self.data,'created')
    def __del__(self):
        print('Data:',self.data,'deleted')
s = Sample()
del s