KnowledgeBoat Logo

Computer Science

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

  1. file1= open("c:\ test.txt", "r")
  2. file1 = open("c:\\ test.txt", "r")
  3. file1 = open(file = "c:\ test.txt", "r")
  4. file1 = open(file = "c:\\s test.txt", "r")

Python Data Handling

3 Likes

Answer

file1 = open("c:\\test.txt", "r")

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

Answered By

2 Likes


Related Questions