arrow
arrow
arrow
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?
Question

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+

Correct option is D

In Python, the rb+ mode opens a file in binary format for both reading and writing. This mode allows you to read existing content and write new data to the file without truncating it.

Important Key Points:

  1. r stands for read.
  2. b stands for binary.
  3. + indicates both reading and writing are allowed.
  4. Using rb+ ensures the file is treated as a binary file, which is essential for non-text files like images, executables, or serialized data.

Knowledge Booster:

  • (a) ab: Opens the file in binary append mode (writing only, at the end of the file).
  • (b) wb: Opens the file in binary write mode (truncates the file if it exists).
  • (c) r+: Opens the file in text mode for both reading and writing (not suitable for binary files).

Free Tests

Free
Must Attempt

DSSSB PGT Political Science PYP (13 July 2025 Shift 2)

languageIcon English
  • pdpQsnIcon300 Questions
  • pdpsheetsIcon300 Marks
  • timerIcon180 Mins
languageIcon English
Free
Must Attempt

UP GIC Lecturer Civics Held on 19 Sept. 2021

languageIcon English
  • pdpQsnIcon120 Questions
  • pdpsheetsIcon300 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

BPSC TRE 1 English Class 11 to 12 (22 July 2024)

languageIcon English
  • pdpQsnIcon120 Questions
  • pdpsheetsIcon120 Marks
  • timerIcon120 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
383k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow