hour = 4minute = 3"{:0>2}:{:0>2}".format(hour,minute)# prints 04:03
"{:0>3}:{:0>5}".format(hour,minute)# prints '004:00003'
"{:0<3}:{:0<5}".format(hour,minute)# prints '400:30000'
"{:$<3}:{:#<5}".format(hour,minute)# prints '4$$:3####'
>>> help(str.zfill)Help on method_descriptor:
zfill(...)S.zfill(width) -> str
Pad a numeric string S with zeros on the left, to fill a fieldof the specified width. The string S is never truncated.
# input list of strings that we want to prepend zerosIn [71]: list_of_str = ["101010", "10101010", "11110", "0000"]
# prepend zeros to make each string to length 8, if length of string is less than 8In [83]: ["0"*(8-len(s)) + s if len(s) < desired_len else s for s in list_of_str]Out[83]: ['00101010', '10101010', '00011110', '00000000']