Destructors: Class Def
Destructors: Class Def
Destructors
Destructors are called when an object is about to be
destroyed. Although not as commonly used in Python
due to its automatic garbage collection, the __del__ method can be defined to
handle the destruction phase of an object.
class Car:
def __del__(self):
print(“The car is being destroyed.”)
# Outputs: The car is being destroyed.
9.3. Inheritance
Inheritance allows us to define a class that inherits all the methods and
properties from another class. The parent class is called the base class, and the class
that inherits from it is called the derived class.
138