Which out of the following mode is required to be used while opening a binary…
2023
Which out of the following mode is required to be used while opening a binary file to allow read as well as write operations in a Python program?
- A.
ab
- B.
wb
- C.
r+
- D.
rb+
Attempted by 1298 students.
Show answer & explanation
Correct answer: D
Answer: rb+ opens a binary file for both reading and writing without truncating the file.
Key details:
rb+ opens the file in binary mode and allows both reading and writing. It does not truncate the existing file content.
The file pointer is placed at the beginning, so you can read existing data or overwrite from the start.
Equivalent mode: 'r+b' is the same as 'rb+'.
Other related modes (for contrast):
wb — open in binary write mode and truncate the file (write-only).
ab — open in binary append mode (write-only), does not allow reading.
r+ — open for reading and writing but in text mode (not binary); use rb+ for binary read/write.