When opening a file, what mode will you use to read the data from the file?

Questions & AnswersCategory: PythonWhen opening a file, what mode will you use to read the data from the file?
Geek Boy Staff asked 2 years ago

When opening a file, what mode will you use to read the data from the file?
a. mode = ‘b’
b. mode = ‘wb’
c. mode = ‘w’
d. mode = ‘r’

1 Answers
Geek Boy Staff answered 2 years ago

d. mode = ‘r’

Explanation:

‘r’: open for reading (default)

‘w’: open for writing, truncating the file first

‘x’: open for exclusive creation, failing if the file already exists

‘a’: open for writing, appending to the end of file if it exists

‘b’: binary mode

‘t’: text mode (default)

‘+’: open for updating (reading and writing)