मराठी

How many file modes can be used with the open() function to open a file? State the function of each mode.

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 7: Data File Handling - EXERCISE [पृष्ठ १४५]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 7 Data File Handling
EXERCISE | Q 7. | पृष्ठ १४५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×