class Loud:
    def __enter__(self):
        print("Entering the block.")
        return self   # whatever this returns becomes the "as x" value

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("Leaving the block — this runs even if something went wrong inside it.")

with Loud() as x:
    print("Inside the block.")