Skip to main content

← All terms Β· Errors & control flow

Context manager

An object usable with `with`. Guarantees cleanup even on exception β€” `open()`, locks, DB sessions.

Learn this interactively:

Open lesson lesson-108 β†’

Related β€” Errors & control flow

ExceptionAn object that signals something went wrong. Raised with `raise`, caught with `t…try / except / finallyHandle exceptions. `finally` always runs (cleanup). Catching `Exception` is usua…EAFPβ€œEasier to Ask Forgiveness than Permission”. Idiomatic Python: try the operation…