hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    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

    CDP Subject Test 01

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

    EVS Subject Test 01

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

    CTET Paper-I PYP (07 July 2024)

    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
    340k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow