Skip to main contentSkip to solution

Match List-I with List-II

List-I - CommandList-II - Explanation
(A) fileobject=open("test.txt","r+")(I) Opens the file in binary and read-only mode.
(B) fileobject=open("test.txt","+a")(II) Opens the file in read,write and binary mode. If the file already exists, the contents will be overwritten. If the file doesn’t exist, then a new file will be created.
(C) fileobject=open("test.dat","+wb")(III) Opens the file in append and read mode. If the file doesn’t exist, then it will create a new file.
(D) fileobject=open("test.dat","rb")(IV) Opens the file in both read and write mode.

Solution

✅ Correct Option: 1
List IList II
(A) open("test.txt","r+")(IV) Opens the file in both read and write mode
(B) open("test.txt","+a")(III) Opens the file in append and read mode; creates it if it doesn't exist
(C) open("test.dat","+wb")(II) Opens the file in read, write and binary mode; overwrites existing contents or creates a new file
(D) open("test.dat","rb")(I) Opens the file in binary and read-only mode

The "+" sign adds the missing ability: "r+" gives read and write, "a+" gives append and read, and "wb+" gives write, read and binary.

"w" overwrites an existing file, while "a" keeps the old contents and adds at the end.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question