Here is a quick table for reference when doing text formatting. For a detailed explanation of how text formatting works, keep reading.
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:
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. ...