python string format
- declare: class string.Formatter
- printf:
'{2}, {1}, {0}'.format('a', 'b', 'c')
'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
'Coordinates: 37.24N, -115.81W'
points = 19
total = 22
'Correct answers: {:.2%}.'.format(points/total)
'Correct answers: 86.36%'
from string import Template
s = Template('$who likes $what')
s.substitute(who='tim', what='kung pao')
'tim likes kung pao'