Computer Science

To open a file c:\test.txt for writing, we should use the statement:

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

Python Data Handling

2 Likes

Answer

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

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", "w") is the correct statement to open a file for writing. The access mode "w" indicates that the file should be opened in write mode.

Answered By

1 Like


Related Questions