English

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? - Computer Science (Python)

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:

  1. File Type: The extension .dat Usually indicates a binary file.
  2. Read-Only Mode: In Python, the character 'r' is used for reading. Adding ‘b’ specifies that the file should be opened in binary mode.
  3. 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?
2025-2026 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×