BGE python - Making double digit numbers below 10

Just a quick question, using realtime text in the BGE im trying to display a countdown, from 02:00 to 00:00. However Im finding it difficult to get the single digit numbers below 10 to come up with a leading 0.

ie 09, 08, 07… 00

Tried several different things, like changing it all into one string with this:

 print ("0",min,":0",sec) 

Thats printing fine, but not working with the realtime text for some reason, Im assuming because its muddling it up into a string or something.

Im sure theres some quick format command which will add a leading 0 in certain cases? I just cant find it anywhere.

You could use the string format something like


Thanks batFINGER, works exactly how I wanted.
I had similar syntax in a earlier attempt, but I think I forgot the .format part and so I kept getting errors. Gah!

Hello, I am also often using the somstring.zfill(numofdigitshere) function, works nicely.

Cool pildanovak, seems a lot less complicated than the other way.

Alternatively, using string formatting:

min = 2
sec = 17
print("%02d:%02d" % (min, sec))