Python·100 questionsWhat is a context manager and with?SaveUpdated: 2026-08-31Answer•with guarantees resource release.•Files, locks, connections.•Custom manager: implement __enter__ and __exit__.•Or use contextlib.contextmanager.•Simplifies safe code.Ask AI to clarifyWas this answer helpful?HelpfulNot helpfulSuggest an improvement