Advertisements
Advertisements
प्रश्न
How many file modes can be used with the open() function to open a file? State the function of each mode.
विस्तार में उत्तर
Advertisements
उत्तर
The main access modes are:
| Mode | Function |
|---|---|
r |
Opens a text file for reading; the file must exist. |
rb |
Opens a binary file for reading. |
w |
Opens a text file for writing; creates a new file or overwrites an existing one. |
wb |
Opens a binary file for writing; creates or overwrites the file. |
a |
Opens a text file for appending at the end; creates it if necessary. |
ab |
Opens a binary file for appending. |
r+ |
Opens a text file for both reading and writing; the file must exist. |
rb+ |
Opens a binary file for both reading and writing. |
w+ |
Opens a text file for reading and writing; overwrites or creates the file. |
wb+ |
Opens a binary file for reading and writing; overwrites or creates it. |
a+ |
Opens a text file for reading and appending. |
ab+ |
Opens a binary file for reading and appending. |
The b indicates binary mode and + indicates both reading and writing.
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
