finally — Advanced Playground
Block that always executes after try/except, used for cleanup
Python Playground
Output
Click "Run" to execute your codefinally runs even when a generator is closed, when a loop is broken, or when sys.exit() is called. It truly always executes.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?