December 2015
Intermediate to advanced
416 pages
7h 15m
English
CHAPTER 21
![]()
Formatting
Here is a quick table for reference when doing text formatting. For a detailed explanation of how text formatting works, keep reading.

Decimal Numbers
Try running the following program, which prints out several random numbers.
import randomfor i in range(10): x = random.randrange(20) print(x)
The output is left justified and numbers look terrible:
161320103181145
We can use string formatting to make the list of numbers look better by right justifying them. The first step is to use the format command on the string. ...
Read now
Unlock full access