Python:Formatting

From Progzoo
Revision as of 02:40, 21 November 2009 by Spoon! (talk | contribs) (Created page with '{{String Functions}} You can format numbers using the <code>%</code> operator. See Format Printing for details of some other options that are available. <question> You can bu...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

You can format numbers using the % operator. See Format Printing for details of some other options that are available.

You can build a string using the % operator. The %8d place holder will ensure that the number takes exactly 8 spaces.

If you need to provide more than one argument on the right side, then they will need to be grouped into a tuple.

The output with "Number:%8d" prints a decimal in 8 spaces:

Number:   12345


[Font] [Default] [Show] [Resize] [History] [Profile]