In Python 2 (and Python 3) you can do:
print "%02d" % (1,)
Basically % is like printf
or sprintf
(see docs).
For Python 3.+, the same behavior can also be achieved with format
:
print("{:02d}".format(1))
For Python 3.6+ the same behavior can be achieved with f-strings:
print(f"{1:02d}")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…