226k views
0 votes
Which statement opens a text file for the purpose of retrieving the information it contains?

a. aFile = open("", "a")
b. aFile = open("", "w")
c. aFile = open("", "s")
d. aFile = open("", "r")

1 Answer

5 votes

Final answer:

The correct statement to open a text file for reading is 'd. aFile = open("", "r")' where 'r' stands for reading mode, which is used when the file is being opened to retrieve its information without modifications.

Step-by-step explanation:

The correct statement for opening a text file for the purpose of retrieving the information it contains is d. aFile = open("", "r").

Each character in the mode string represents a different mode in which the file is opened. The "r" stands for "read" mode, which means the file is being opened for reading and no changes will be made to the content of the file. This is the default mode if none is specified. Here's a brief explanation of other modes:

  • "w" is for "write" mode, where a new file is created (or an existing file is overwritten).
  • "a" is for "append" mode, which adds to the end of the file without altering its existing contents.
  • N.B.: There is no "s" mode in file operations in most programming languages.

User David Glenn
by
8.4k points