Computer Science
In which of the following file modes, the existing data of file will not be lost ?
- 'rb'
- ab
- w
- w + b
- 'a + b'
- wb
- wb+
- w+
- r+
Python File Handling
10 Likes
Answer
'rb', ab, a + b, r+
Reason —
- 'rb' — This mode opens the file for reading in binary mode. It will not erase the existing data and allows reading of the file.
- 'ab' — This mode opens the file for appending in binary mode. It will not erase the existing data but will append new data to the end of the file.
- 'a + b' — This mode opens the file for reading and appending. It will not erase the existing data and allows both reading from and appending to the file.
- 'r+' — This mode opens the file for reading and writing. It will not erase the existing data and allows both reading from and writing to the file.
Answered By
4 Likes
Related Questions
What would be the data type of variable data in following statements ?
- data = f.read()
- data = f.read(10)
- data = f.readline()
- data = f.readlines()
How are following statements different ?
- f.readline()
- f.readline().rstrip()
- f.readline().strip()
- f.readline.rstrip('\n')
What are text files ?
What are binary files ?