Problem Statement - B01A-2015
How is __init( ) __different from __del ( )__ ?
Solution
CSKC| Created: 11-Jan-2019 | Updated: 22-Feb-2019|CBSE12A-2015
How is __init( ) __different from __del ( )__ ?
|
__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
CSKC| Created: 11-Jan-2019 | Updated: 22-Feb-2019|CBSE12A-2015