Skip to main content

← All terms · Errors & control flow

EAFP

“Easier to Ask Forgiveness than Permission”. Idiomatic Python: try the operation, catch the exception, rather than pre-checking.

Learn this interactively:

Open lesson lesson-103

Related — Errors & control flow

ExceptionAn object that signals something went wrong. Raised with `raise`, caught with `ttry / except / finallyHandle exceptions. `finally` always runs (cleanup). Catching `Exception` is usuaContext managerAn object usable with `with`. Guarantees cleanup even on exception — `open()`, l