of Py & print

d Signed integer decimal.
i Signed integer decimal.
o Unsigned octal.
u Unsigned decimal.
x Unsigned hexadecimal (lowercase).
X Unsigned hexadecimal (uppercase).
e Floating point exponential format (lowercase).
E Floating point exponential format (uppercase).
f Floating point decimal format.
F Floating point decimal format.
g Floating point format. Uses exponential format if exponent is greater than -4 or less than precision, decimal format otherwise.
G Floating point format. Uses exponential format if exponent is greater than -4 or less than precision, decimal format otherwise.
c Single character (accepts integer or single character string).
r String (converts any python object using repr()).
s String (converts any python object using str()).
% No argument is converted, results in a "%" character in the result.

Usage: print "%d etc ... %d" % (3*3, 4-1)

1 comment:

:: unexistance :: said...

for currency, use
print "%6.2d" (1500)