Look into string.format
- https://docs.python.org/3.1/library/string.html#formatspec
The specification language is fairly opaque but you’ll only generally need a few useful snippets.
A whole number
>>> "{:03d}".format(100)
'100'
>>>
With leading zeros:
>>> "{:03d}".format(99)
'099'
Temperature (or a decimal number with 5 digits and 2 decimal places):
>>> "{:5.2f}".format(19.22)
'19.22'
Pressure (or a decimal number with 7 digits and 2 decimal places):
>>> "{:7.2f}".format(1020.22)
'1020.22'
And you can use these at any point in your text to add your number:
>>> "The temperature is {:5.2f}C".format(22.15)
'The temperature is 22.15C'
And, of course, from a variable too:
temperature = 19.2524
>>> "The temperature is {:5.2f}C".format(temperature)
'The temperature is 19.25C'