Python 3 for Windows Administrators (early access)
Installing Python on Windows • 17min
0 / 3 lessons complete
Section Overview
Free lesson
Text | 1 min
Downloading and Installing Python on Windows
Free lesson
Text | 8 min
Installing and configuring VS Code for Python
Free lesson
Text | 8 min
Python Basics • 27min
0 / 6 lessons complete
Executing Python Code
Free lesson
Text | 3 min
Python 3 Syntax
Free lesson
Text | 5 min
Help! Python Keywords
Free lesson
Text | 4 min
Printing to the console!
Text | 6 min
Python Operators
Text | 4 min
Section Review
Quiz | 5 min
Python Variables • 5min
0 / 1 lessons complete
Sign up to access this lesson
Click here to sign up and get access to this lesson!

Saving Progress...
Printing to the console!
Printing output in Python is something you will need to do quite often to understand things are going in your python program. It can be used for debugging, show progress or just to display information that may be important to whomever is running the script.
Use the Python console below to practice what you learn in this lesson:
We can start by using print in its most simple form:
print("This is a printed line")
Use the percent sign to substitute
We can use the %s operator to replace text inside of our string:
print("This is my number %s" %(25))
This outputs:
This is my number 25
Center Method
You can use the center method to add even padding on either side of your python:
print("This is a printed line".center(80,'-'))
This will output a line like this:
-----------------------------This is a printed line-----------------------------
Left and right adjusting
print("This is a printed line".ljust(80,'-'))
This outputs a line like this:
This is a printed line----------------------------------------------------------
print("This is a printed line".rjust(80,'-'))
----------------------------------------------------------This is a printed line
Tabbing Output
If we escape the t by preceeding it with a backslash (like: \t) we can insert tabs into our output:
print("First name\t\tLast Name")
print("Paul\t\t\tHill")
print("Joe\t\t\tFriday")
print("Jonathan\t\tMarston")
This will show the following:
First name Last Name
Paul Hill
Joe Friday
Jonathan Marston
This isn't optimate because you will notice that we need to modify the number of tabs based on how many characters are in our output.
Column Alignment with %
We can also use the % method to format our print statements:
print("First name Last Name")
print("%-*s %s" % (19, 'Paul', 'Hill'))
print("%-*s %s" % (19, 'Joe', 'Friday'))
print("%-*s %s" % (19, 'Jonathan', 'Marston'))
This outputs:
First name Last Name
Paul Hill
Joe Friday
Jonathan Marston
Sign up to access the rest of this lesson
You must either log in or sign up to access this lesson.

Saving Progress...