Bird
Raised Fist0

Why is it important to close a file after opening it in Python?

hard🧠 Conceptual Q10 of Q15
Python - File Handling Fundamentals
Why is it important to close a file after opening it in Python?
ABecause Python crashes if files are not closed
BTo free system resources and avoid data loss
CTo make the file read-only
DTo delete the file automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand resource management

    Open files use system resources like memory and file handles.
  2. Step 2: Importance of closing files

    Closing files frees these resources and ensures data is written properly.
  3. Final Answer:

    To free system resources and avoid data loss -> Option B
  4. Quick Check:

    Close files to free resources and save data = A [OK]
Quick Trick: Always close files to save data and free resources [OK]
Common Mistakes:
MISTAKES
  • Thinking Python crashes if not closed
  • Believing closing makes file read-only
  • Assuming closing deletes the file

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes