Bird
0
0

What happens if you try to read from a file opened in write mode ('w') in Python?

easy📝 Conceptual Q1 of 15
Python - File Handling Fundamentals
What happens if you try to read from a file opened in write mode ('w') in Python?
AIt returns an empty string
BIt reads the content normally
CIt raises an error because the file is not open for reading
DIt appends the content automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand file modes

    Opening a file in 'w' mode means write-only; reading is not allowed.
  2. Step 2: Behavior when reading in write mode

    Trying to read from a write-only file causes an error.
  3. Final Answer:

    It raises an error because the file is not open for reading -> Option C
  4. Quick Check:

    File mode 'w' disallows reading = C [OK]
Quick Trick: Write mode files cannot be read; use 'r' or 'r+' for reading [OK]
Common Mistakes:
  • Assuming 'w' mode allows reading
  • Confusing 'w' with 'r+'
  • Expecting empty string instead of error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes