Bird
0
0

Which of the following is the correct syntax to open a file named log.txt for appending text in Python?

easy📝 Syntax Q12 of 15
Python - File Handling Fundamentals
Which of the following is the correct syntax to open a file named log.txt for appending text in Python?
Aopen('log.txt', 'r')
Bopen('log.txt', 'w')
Copen('log.txt', 'a')
Dopen('log.txt', 'x')
Step-by-Step Solution
Solution:
  1. Step 1: Identify the mode for appending

    Mode "a" opens the file for appending, adding new content at the end.
  2. Step 2: Check syntax correctness

    The syntax open('log.txt', 'a') is correct for appending text.
  3. Final Answer:

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

    Append mode = "a" [OK]
Quick Trick: Append mode is always "a" [OK]
Common Mistakes:
  • Using "r" which is read-only
  • Using "w" which overwrites the file
  • Using "x" which creates new file only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes