finally — Expert Playground
Block that always executes after try/except, used for cleanup
Python Playground
Output
Click "Run" to execute your codeCPython duplicates the finally block's bytecode into both the normal and exception paths. SETUP_FINALLY pushes an entry onto the block stack that the VM uses to find the cleanup code.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?