Python Programming - Exception Handling - Discussion

Discussion Forum : Exception Handling - General Questions (Q.No. 37)
37.
What is the purpose of the with statement in Python for file handling?
It raises exceptions
It terminates the program
It ensures proper resource cleanup
It defines custom exception classes
Answer: Option
Explanation:
The with statement is used for file handling in Python and ensures proper resource cleanup by automatically closing the file when the block is exited, even if an exception occurs.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.