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?

Show Hint

Modes with a plus sign allow writing too. Pick the mode that only reads a binary file.
Updated On: Oct 20, 2026
  • a
  • rb
  • r+
  • rb+
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Recall the common file modes:
'r' opens a text file for reading only. Adding 'b' means a binary file, so 'rb' is read only for binary files.
'a' opens for appending (writing at the end). A plus sign adds the second ability, so 'r+' and 'rb+' both read and write.

Step 2: Check option (A) 'a':
'a' is for adding data to the end of a file. It is not a read mode.

Step 3: Check option (B) 'rb':
The file pqr.dat is a binary data file. 'rb' opens it for reading only. The file cannot be written. This fits the question.

Step 4: Check option (C) 'r+':
'r+' opens for reading and writing, so it is not read only.

Step 5: Check option (D) 'rb+':
'rb+' is also read and write for a binary file, so it is not read only.

Final Answer:
The only read only mode in the list is 'rb', option (B).
Was this answer helpful?
0
0

Top CBSE CLASS XII file handling Questions