Press "Enter" to skip to content

Python Example 4 – Print Formatting

Example #4 Print Formatting in Python

This post will use a trinket to display the source demoing the use of print formatting in Python. The source is commented for context, the output may be seen in the trinket by running it.

Demoing Print Formatting

*Note: With the trinket widget you may toggle between the code (Pencil icon) and the output (Play button). Please visit my GitHub if you would like to look at all of the Python source code. Laszlo’s GitHub.

Demoing Print Formatting with Python 3 Syntax in Python 2

*At the time of this post trinket does not support importing __future__, which allows the use of the explicitly requested feature of Python 3 in Python 2. Bellow is the source example.

#Import Python 3 features
from __future__ import print_function

#Python 3 in Python 2
print(‘hello’)

#Python 3 format method
print(‘One: {x}’.format(x=’INSERT!’))

Leave a Reply

Your email address will not be published. Required fields are marked *