print("{:0*number of characters here*d}".format(my_integer)) # Example with two characters, one of which is a leading zero print("{:02d}".format(2))