KnowledgeBoat Logo

Computer Science

In which of the following file modes, the existing data of file will not be lost ?

  1. 'rb'
  2. ab
  3. w
  4. w + b
  5. 'a + b'
  6. wb
  7. wb+
  8. w+
  9. r+

Python File Handling

10 Likes

Answer

'rb', ab, a + b, r+

Reason —

  1. 'rb' — This mode opens the file for reading in binary mode. It will not erase the existing data and allows reading of the file.
  2. '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.
  3. '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.
  4. '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