KnowledgeBoat Logo

Computer Science

When a file is opened for output in append mode, what happens when

(i) the mentioned file does not exist

(ii) the mentioned file does exist.

Python File Handling

2 Likes

Answer

When a file is opened for output in append mode ("a" mode) in Python, the behaviour differs depending on whether the mentioned file already exists or not:

(i) If the mentioned file does not exist — If the file specified in the open() function does not exist, Python will create a new file with the given name. The file will be opened for writing, and any data written to it will be appended to the end of the file.

(ii) If the mentioned file does exist — If the file specified in the open() function already exists, the data in the file is retained and new data being written will be appended to the end of the file.

Answered By

2 Likes


Related Questions