Python Programming - Functions - Discussion

Discussion Forum : Functions - General Questions (Q.No. 75)
75.
What is the purpose of the __enter__ and __exit__ methods in a Python class?
To define the initialization and cleanup methods of a class.
To define methods for adding and removing elements in a class.
To create context managers for resource management.
To define methods for comparison operations in a class.
Answer: Option
Explanation:
The __enter__ and __exit__ methods in a Python class are used to create context managers for resource management, allowing proper setup and cleanup.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.