In Python 2.7, you can format this value with
>>> month = 9
>>> '{:02}'.format(month)
'09'
here 2 in {: 02} indicates the conversion of the input digit into 2 characters by the prefix '0'. If the input digit has a length of 2, then this digit will remain unchanged.
source
share