ashchristopher ashchristopher - 16 days ago 5
Python Question

Display number with leading zeros

Given:

a = 1
b = 10
c = 100


I want to display a leading zero for all numbers with less than 2 digits, i.e.:

01
10
100

Answer

Here you are:

print "%02d" % (1,)

Basically % is like printf or sprint.