Bird
0
0

You want to open a file to read and write without truncating it, and create it if it does not exist. Which mode is correct?

hard📝 Application Q9 of 15
Python - File Handling Fundamentals
You want to open a file to read and write without truncating it, and create it if it does not exist. Which mode is correct?
A"r+"
B"a+"
C"w+"
D"x+"
Step-by-Step Solution
Solution:
  1. Step 1: Understand "a+" mode

    "a+" opens file for reading and appending, creates if missing, does not truncate.
  2. Step 2: Compare with other modes

    "r+" errors if missing, "w+" truncates, "x+" errors if exists.
  3. Final Answer:

    "a+" mode -> Option B
  4. Quick Check:

    Read/write append without truncate = a+ [OK]
Quick Trick: Use "a+" to read/write append and create if missing [OK]
Common Mistakes:
  • Using "r+" which fails if file missing
  • Using "w+" which truncates file
  • Using "x+" which errors if file exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes