Answer
Context managers use __enter__ and __exit__.
Automatically handle resource cleanup.
Used for files, network connections, locks.
Can create custom managers using contextlib.
Automatically handle resource cleanup.
Used for files, network connections, locks.
Can create custom managers using contextlib.