Bird
Raised Fist0

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

easy🧠 Conceptual Q1 of Q15
Python - Context Managers
Why is it important to close a file after opening it in Python?
ATo increase the file size
BTo make the file read-only
CTo delete the file automatically
DTo free system resources and avoid data corruption
Step-by-Step Solution
Solution:
  1. Step 1: Understand file resource usage

    When a file is opened, system resources are allocated to manage it.
  2. Step 2: Importance of closing files

    Closing a file releases these resources and ensures data is saved properly.
  3. Final Answer:

    To free system resources and avoid data corruption -> Option D
  4. Quick Check:

    Closing files = Free resources [OK]
Quick Trick: Always close files to free resources and save data [OK]
Common Mistakes:
MISTAKES
  • Assuming files close automatically
  • Ignoring resource leaks
  • Thinking closing deletes files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes