English

Write the file mode that will be used for opening the following file. Also, write the Python statement to open the following file: a text file “example.txt” in both read and write mode

Advertisements
Advertisements

Question

Write the file mode that will be used for opening the following file. Also, write the Python statement to open the following file:

a text file “example.txt” in both read and write mode

Short/Brief Note
Advertisements

Solution

The mode that will be used for opening given file is -

Read and Write (<r+> or <+r>) : This mode is used to open the file for reading and writing. The File Offset is positioned at the beginning of the file. It will raise an I/O error if the file does not exists.

Example - file = open("example.txt","r+")
          file.close()
shaalaa.com
Types of Files in Python
  Is there an error in this question or solution?
Chapter 2: File Handling in Python - Exercise [Page 37]

APPEARS IN

NCERT Computer Science [English] Class 12
Chapter 2 File Handling in Python
Exercise | Q 3. a) | Page 37
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×