Python Intermediate #8 - Simple text formatting in Python

In this post, I show a simple method for formatting text in Python.  In the example, we ask the user for three inputs:  name, occupation, and location.

I then show two different methods for printing the inputs into a sentence.

The first method shows a combination of the objects "name", "occupation", and "location" inserted into their correct positions between text.



The results of executing this code are as follows:



Instead of inserting the object names in between the text, we can use %s to indicate that the contents of an object will be inserted at that location.  The objects to be inserted then follow the % symbol.  This coding (with the original print statement commented out) is given below:



The results of executing this code are as follows:

Comments