String Output Width and Precision : Output Format « Development « Python
- Python
- Development
- Output Format
String Output Width and Precision

from math import pi
print '%10f' % pi # Field width 10
print '%10.2f' % pi # Field width 10, precision 2
print '%.2f' % pi # Precision 2
print '%.5s' % 'Guido van Rossum'
print '%.*s' % (5, 'Guido van Rossum')
Related examples in the same category