Bird
0
0

Which of the following is the correct way to open a file for appending text in Python?

easy📝 Syntax Q12 of 15
Python - File Reading and Writing Strategies
Which of the following is the correct way to open a file for appending text in Python?
Aopen('file.txt', 'w')
Bopen('file.txt', 'r')
Copen('file.txt', 'a')
Dopen('file.txt', 'x')
Step-by-Step Solution
Solution:
  1. Step 1: Identify append mode

    Mode 'a' opens the file for appending, adding data at the end without deleting existing content.
  2. Step 2: Check other modes

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

    open('file.txt', 'a') -> Option C
  4. Quick Check:

    Append mode = 'a' [OK]
Quick Trick: Use 'a' to add data without deleting old [OK]
Common Mistakes:
  • Using 'w' when append is needed
  • Confusing 'r' with append mode
  • 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