0% found this document useful (0 votes)
4 views3 pages

Python File Processing Modes Explained

Python supports three file-processing modes: read only, write only, and read-write. The 'w' mode overwrites existing files, while 'a' mode appends data to existing files. Additionally, 'r+' allows reading and writing from the beginning, while 'w+' overwrites the file, and 'rb+' does the same in binary format.

Uploaded by

qwertyhema66
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Python File Processing Modes Explained

Python supports three file-processing modes: read only, write only, and read-write. The 'w' mode overwrites existing files, while 'a' mode appends data to existing files. Additionally, 'r+' allows reading and writing from the beginning, while 'w+' overwrites the file, and 'rb+' does the same in binary format.

Uploaded by

qwertyhema66
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q.

What are the different file-processing modes


supported by Python?

Answer =

Python provides three modes to process files:

1. Read only mode


2. Write only mode
3. Read-write mode

Q. What is the difference between "w" and "a" modes?

Answer =

"w" mode :- If file exists, python will delete all data of the file.

"a" mode :- If file exists, the data in the file is retained and new data being written will be
appended to end.

Q. Differentiate between file modes r+ and w+ with


respect to python.

Answer =

• r+ opens a file for both reading and writing. The file pointer placed at the beginning of the
file.

• w+ opens a file for both writing and reading. Overwrites the existing file if the file exists. If
the file does not exist, creates a new file for reading and writing.

Q. Differentiate between file modes r+ and rb+ with


respect to Python.

Answer =

r+ opens a file for both reading and writing. The file pointer is placed at the beginning of the
file.
rb+ opens a file for both reading and writing in binary format. The file pointer is placed at the
beginning
of the file.

Q. What would be the data type of variable data in the


following statements?
(a) data = [Link]()

(b) data = [Link](10)

(c) data = [Link]()

(d) data = [Link]()

Answer =

(a) String type.

(b) String type.

(c) String type.

(d) List type.

Q. What are the advantages of saving data in:

(i) Binary form

(ii) Text form

Answer =

(i)
• It is faster and use less memory.
• Computer can easily understand this form.
• We Can Store Any type of Data in it.

(ii)
• It can easily understand by human.
• It can excess easily.

You might also like