Output

% Formatting

>>> f = 12.345
>>> s = 'patrick'
>>> print '%s owes %.2f' % (s, f)
patrick owes 12.34

Dictionary

Using a dictionary:

>>> t = {'b': 'banana', 'a': 'apple'}
>>> print "%(a)s %(b)s" % t
apple banana

Justify

>>> print '[%-30s]' % 'southampton'
[southampton                   ]

Width

Maximum (.):

>>> print '[%-.5s]' % 'southampton'
[south]

Minimum:

>>> print '[%30s]' % 'southampton'
[                   southampton]

pprint