Class / inside block code processing

from time import sleep

class TestClass:
    def __init__(self, id): = id
        print("Creating object id = " + str(

    def __del__(self):
        print("Deleting object id = " + str(

my_obj = TestClass(1)
print("Ten seconds passed")

In the above example, I am not sure to fully understand why the sleep function intervene before the method del.
Why Python doesn’t: 1/ execute the init method 2/execute the del method 3/ execute the sllep function 4/ print “Ten seconds passed”?

The __del__ dunder method is called when the object is about to be destroyed, documentation.
In your example this won’t occur until the script itself is finishing. Unless you took steps to remove this instance beforehand then it would only have that method called at the very end of the script.
So your guess at the execution order is off because __del__ is not called when you think it is.

Thank you very much, it is cristal clear now.