Written by Sean Behan on Wed Nov 20th 2013

You can use string interpolation in combination with a dictionary for simple formatting.

print "My name is %(name)s and I have $%(change)0.2f in change in my pocket!" % { 'name': 'Sean', 'change': 00.23 }
# My name is Sean and I have $0.23 in change in my pocket!

For the precision of floats you you need to use "0.2f" after the interpolation expression, where the "2" is how many decimal places to use.

Tagged with..
#Python #String Interpolation

Just finishing up brewing up some fresh ground comments...