Match List-I with List-II
List-I - Command List-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.
Match List-I with List-II
| List-I - Command | List-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 I | List 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.
Related questions:
2026: 13 May Shift 2
2025: 15 May Shift 2
2025: 16 May Shift 1
2026: 26 May Shift 1
2026: 20 May Shift 1