Anshul Gupta
Anshul Gupta

Reputation: 277

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

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

Upvotes: 2

Views: 5518

Answers (3)

Sanidhya
Sanidhya

Reputation: 191

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

Upvotes: 0

ichramm
ichramm

Reputation: 6642

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.

Upvotes: 1

TheHappyBee
TheHappyBee

Reputation: 303

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).

Upvotes: 3

Related Questions