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?
