I am new in python. In the following line '{0:6}{1:02d}'.format(date, hour)
I figured out that hour should be 0 filled to two digits. But I can't figure out what it is formatting date to be. afaik, both date and hour are int values here.
I am new in python. In the following line '{0:6}{1:02d}'.format(date, hour)
I figured out that hour should be 0 filled to two digits. But I can't figure out what it is formatting date to be. afaik, both date and hour are int values here.
{0:6} is just going to take the 0th argument (date) and print it with a minimum of 6 characters. It can be an integer, a string, ... Nothing else special there. It is a guess at what format was intended for date (ie. May1st, 5/1, ...)
You are correct about the interpretation of the {1:02d} which is the hour field print in a minimum of 2 decimal digits with 0's to pad.
Try it and see:
a = 10
b = 6
print('{0:6}{1:02}'.format(a, b))
#output => ' 1006'
So like 02 adds "0"s to the variable until it is of 2 length. Just adding a number (6) will add spaces to the front until the variable length is 6.
Python's Common String Operator's Docs has more.