For a newly created file, is there any difference between write() and append() methods?

Question:

For a newly created file, is there any difference between write() and append() methods, in Python?

Asked By: Anshul Gupta

||

Answers:

The write method overwrites the content in a text file while the append method appends text to the file.

If there is nothing in the file however, then write is the same as append (they both write new text into the file).

Answered By: TheHappyBee

When you open a file in append mode, the seek pointer points to the end of the file (the pointer position will be non-zero if the file is not empty).

On new (empty) files, the end is equal to the beginning. So appending is the same as overwriting.

Answered By: ichramm

No, there is no difference if file is newly created.

Answered By: Sanidhya
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.