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

UPTET Paper 1: PYP Held on 23rd Jan 2022 (Shift 1)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Social Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Maths & Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 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
354k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow