Bird
0
0

Which of the following is the correct way to open notes.txt for appending text in Python?

easy📝 Conceptual Q2 of 15
Python - File Handling Fundamentals
Which of the following is the correct way to open notes.txt for appending text in Python?
Awith open('notes.txt', 'r') as file:
Bwith open('notes.txt', 'a') as file:
Cwith open('notes.txt', 'w') as file:
Dwith open('notes.txt', 'x') as file:
Step-by-Step Solution
Solution:
  1. Step 1: Identify append mode

    Mode 'a' opens a file for appending text.
  2. Step 2: Check other modes

    'r' is read-only, 'w' overwrites, 'x' creates new file and errors if exists.
  3. Final Answer:

    with open('notes.txt', 'a') as file: -> Option B
  4. Quick Check:

    Append mode is 'a' [OK]
Quick Trick: Use mode 'a' to append text to files [OK]
Common Mistakes:
  • Using 'w' which overwrites file
  • Using 'r' which is read-only
  • Using 'x' which fails if file exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes