Printing to the console!
Server Academy Members Only
Sorry, this lesson is only available to Server Academy members. Create a free account now to get instant access to this and more free courses. Click the Sign Up Free button below to get access to our free courses now, or sign in if you have an account.
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 on the right to practice what you learn in this lesson.
Interactive Python Console
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))
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,'-'))
Left and right adjusting
Left:
print("This is a printed line".ljust(80,'-'))
Right:
print("This is a printed line".rjust(80,'-'))
Tabbing Output
If we escape the t by preceding 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 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'))
Server Academy Members Only
Want to access this lesson? Just sign up for a free Server Academy account and you'll be on your way. Already have an account? Click the Sign Up Free button to get started..

Saving Progress...
Python 3 Fundamentals
Installing Python on Windows • 1hr 17min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 1 min min
Downloading and Installing Python on Windows
Free Preview Lesson
Text | 8 min min
Installing and configuring VS Code for Python
Free Preview Lesson
Text | 8 min min
Lab: Installing Python
Free Preview Lesson
Devops Lab | 60 min
Python Basics • 28min
0 / 7 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min min
Executing Python Code
Free Preview Lesson
Text | 3 min min
Python 3 Syntax
Free Preview Lesson
Text | 5 min min
Help! Python Keywords
Free Preview Lesson
Text | 4 min min
Printing to the console!
Free Preview Lesson
Text | 5 min min
Python Operators
Free Preview Lesson
Text | 4 min min
Section Review
Free Preview Lesson
Quiz | 5 min min
Python Variables • 41min
0 / 8 lessons complete
Section Overview
Free Preview Lesson
Text | 4 min min
Casting
Free Preview Lesson
Text | 4 min min
Strings
Free Preview Lesson
Text | 5 min min
Booleans
Free Preview Lesson
Text | 8 min min
User Input
Free Preview Lesson
Text | 2 min min
Numbers
Free Preview Lesson
Text | 7 min min
NoneType
Free Preview Lesson
Text | 5 min min
Assignment: Write a Mad Libs Script
Free Preview Lesson
Text | 6 min min
Even more Python Variables! • 41min
0 / 6 lessons complete
Python Lists
Free Preview Lesson
Text | 8 min min
Python Tuples
Free Preview Lesson
Text | 7 min min
Python Sets
Free Preview Lesson
Text | 7 min min
Frozensets
Free Preview Lesson
Text | 6 min min
Dictionaries
Free Preview Lesson
Text | 8 min min
Iterator and Iterable
Free Preview Lesson
Text | 5 min min
Conditional Statements • 15min
0 / 3 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min min
If Statements
Free Preview Lesson
Text | 6 min min
Try, Except
Free Preview Lesson
Text | 7 min min
Writing Functions • 30min
0 / 5 lessons complete
Section Overview
Free Preview Lesson
Text | 3 min min
Defining Functions
Free Preview Lesson
Text | 4 min min
Importing functions from another file
Free Preview Lesson
Text | 4 min min
Assignment: Rock, paper, scissors
Free Preview Lesson
Text | 12 min min
Assignment: Count Dictionary Words
Free Preview Lesson
Text | 7 min min
Python Loops • 23min
0 / 5 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min min
For In Loops
Free Preview Lesson
Text | 5 min min
While Loops
Free Preview Lesson
Text | 5 min min
Nested Loops
Free Preview Lesson
Text | 3 min min
Python Loops Challenge!
Free Preview Lesson
Text | 8 min min
Python PIP and Modules • 18min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 3 min min
Installing Python PIP
Free Preview Lesson
Text | 4 min min
Installing Modules with PIP
Free Preview Lesson
Text | 5 min min
Importing Modules
Free Preview Lesson
Text | 6 min min
RegEx • 26min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 4 min min
Regex 101
Free Preview Lesson
Text | 10 min min
Importing Regex and manipulating strings
Free Preview Lesson
Text | 7 min min
Regex Challenge!
Free Preview Lesson
Text | 5 min min
Working with APIs • 12min
0 / 3 lessons complete
Making HTTP Requests
Free Preview Lesson
Text | 3 min min
Working with JSON
Free Preview Lesson
Text | 5 min min
Get your weather with theu00a0OpenWeatherMap
Free Preview Lesson
Text | 4 min min
Course Conclusion • 2min
0 / 1 lessons complete