O'Reilly logo

Program Arcade Games: With Python and Pygame, Fourth Edition by Paul Vincent Craven

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 21

image

Formatting

Here is a quick table for reference when doing text formatting. For a detailed explanation of how text formatting works, keep reading.

Taba

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required