I have been using the format:
print 'blah, blah %f' %variable
to put variables into strings. I heard it was more pythonic than the '+str()+' approach, and have got quite used to it. Is there a way of specifying the decimal places added to the string with %f? I have tried rounding the number before supplying the variable.
Thanks
In Python version 2.6 and newer, you can use:
where "0" refers to the first value passed into str.format, ":" says "here comes the format specification", and ".2f" means "floating point number with two decimal places of precision". This is the suggested way of formatting strings now.
Here is the Python Doc Link, please consider: