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 PRT Full Mock - 01

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 Marks
  • timerIcon120 Mins
languageIcon English
Free
Must Attempt

Educational Psychology & Pedagogy - 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon15 Mins
languageIcon English
Free
Must Attempt

DSSSB PRT PYP Held on 7th March 2022 Shift 1

languageIcon English
  • pdpQsnIcon200 Questions
  • pdpsheetsIcon200 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
368k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow