Question:easy

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

The Correct Option is B

Solution and Explanation

Step 1: Sort the four modes by what they allow:
'a' allows writing at the end.
'rb' allows reading only.
'r+' allows reading and writing.
'rb+' allows reading and writing in binary form.

Step 2: Use the plus rule:
Any mode with a plus sign gives both reading and writing. That removes (C) and (D).
The mode 'a' has no reading at all, so (A) is removed too.

Step 3: Check the one that is left:
'rb' has no plus sign and no a or w, so the file can only be read. A .dat file holds binary data, so the b in the mode suits it.
Code such as f1 = open("pqr.dat","rb") opens the file safely for reading.

Final Answer:
The blank is filled with rb, option (B).
Was this answer helpful?
0