Constructor is a special method that executes when we create an object of a class.
Constructor is defined using
car = Car() # print 'Hello world'
Destructors are called when an object gets destroyed. It’s the polar opposite of the constructor, which gets called on creation.
Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc.
Destructor is defined using
print('Destructor called, vehicle deleted.')
car = Vehicle()
Python deletes unneeded objects (built-in types or class instances) automatically to free the memory space.
The process by which Python periodically reclaims blocks of memory that no longer are in use is termed as Garbage Collection.
Python's garbage collector runs during program execution and is triggered when an object's reference count reaches zero.
An object's reference count changes as the number of aliases that point to it changes.