Python 3 Write Texts to File

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 this contents:

Open File to Append

We start off with an existing file with this contents:

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

The final file contents is:

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert