This project demonstrates how to implement a destructor in Python using a simple class.
The program defines a class Demo with:
- A constructor
__init__that initializes an instance variable and prints a message. - A destructor
__del__that prints a message when the object is destroyed.
- Define a class named
Demo. - Inside the class, define the
__init__method:- Initialize an instance variable
statuswith the value"Alive". - Print the value of
status.
- Initialize an instance variable
- Define the
__del__method:- Print a message indicating the object is being destroyed.
- Outside the class:
- Create an instance of the
Democlass. - Delete the object using the
delkeyword.
- Create an instance of the
Add code Here