KnowledgeBoat Logo

Computer Science

To open a file c:\test.txt for appending data, we can give the statement:

  1. fobj = open("c:\\test.txt", "a")
  2. fobj = open("c:\\test.txt", "rw")
  3. fobj = open(file = "c:\test.txt", "w")
  4. fobj = open(file = "c:\\test.txt", "w")

Python Data Handling

3 Likes

Answer

fobj = open("c:\\test.txt", "a")

Reason — The syntax for 'open()' is: <file variable>/<file object or handle> = open(file_name, access_mode). Therefore, according to this syntax, fobj = open("c:\\test.txt", "a") is the correct statement to open a file for writing. The access mode "a" indicates that the file should be opened in append mode.

Answered By

2 Likes


Related Questions