Python 3 Write Texts to File

Last Updated on

This post shows how to write texts to a file in Python 3.

Using Python 3.7.0.

Opening a File for Writing

Before we can write to a file we need to open it first. By writing, we mean either appending or replacing the contents of an existing file.

Open File to Write

This creates a file with these contents:

Open File to Append

We start off with an existing file with these contents:

Then, we run the following codes to complete the texts:

The final file contents are:

Karl San Gabriel

Karl San Gabriel

Professional Software Developer