String formatting characters - looking for details

Steve Holden sholden at holdenweb.com
Wed Feb 7 18:17:07 EST 2001


"Martin Bless" <m.bless at gmx.de> wrote in message
news:3a81cfa2.1708851 at news.muenster.de...
> (1) Where can I find some more details about the string formatting
> characters?
> (2) How  I print hex values with zeros padded left, like 0F or 0A?
> print '%X' % 15  # two digits, wanted
>
> (3) This is from the Python docs - I'm looking for more information on
> how to use the formatting characters.
>
> Thanks,
> Martin
>
[ doc snipped]

1. If you have a UNIX system handy, the man page on printf(3) will tell you
most of what you need to know. I've just loaded Cygwin on my laptop, and
that also has the right stuff in it. Or a "C" library reference book, if you
have one.

2. Leading zeroes can be obtained with a "0" flag, and ".2" specifies a
field width of two characters. The following example should help.

>>> "%0.2X" % 2
'02'

3. See 1.

regards
 Steve





More information about the Python-list mailing list