String formatting characters - looking for details

Martin Bless m.bless at
Wed Feb 7 17:55:49 EST 2001

(1) Where can I find some more details about the string formatting
(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.


------------------- from the Python docs -------- String Formatting Operations 

String objects have one unique built-in operation: the % operator
(modulo) with a string left argument interprets this string as a C
sprintf() format string to be applied to the right argument, and
returns the string resulting from this formatting operation. 

The right argument should be a tuple with one item for each argument
required by the format string; if the string requires a single
argument, the right argument may also be a single non-tuple object.2.5
The following format characters are understood: %, c, s, i, d, u, o,
x, X, e, E, f, g, G. Width and precision may be a * to specify that an
integer argument specifies the actual width or precision. The flag
characters -, +, blank, # and 0 are understood. The size specifiers h,
l or L may be present but are ignored.

More information about the Python-list mailing list