Home Tutorials Python OOP Concepts Destructor
Destructor

Destructor


38. Destructor

Python supports a destructor-like special method named __del__(), which is called when an object is about to be destroyed. It is less commonly used than constructors in typical Python programs.

Syntax

def __del__(self):
    pass

Example

class Demo:
    def __del__(self):
        print("Object destroyed")

obj = Demo()
del obj

Output

Object destroyed
Example

🏋️ Test Yourself With Exercises

Take our quiz on Destructor to test your knowledge.

Browse Quizzes »