Advertisements
Advertisements
Question
Consider the statement given below:
f1 = open(“pqr.dat”,“______”)
Which of the following is the correct file mode to open the file in read only mode?
Options
a
rb
r+
rb+
MCQ
Advertisements
Solution
rb
Explanation:
- File Type: The extension
.datUsually indicates a binary file. - Read-Only Mode: In Python, the character 'r' is used for reading. Adding ‘b’ specifies that the file should be opened in binary mode.
- Why others are wrong:
- ‘a’ is for appending data.
- ‘r+’ allows both reading and writing.
- ‘rb+’ allows reading and writing in binary format.
shaalaa.com
Is there an error in this question or solution?
