There is an even more specific string function ....
n = 2
digits = 3
ns = str(n).zfill(digits)
print(ns) # 002
These string functions work with Python2 and Python3.
Gribouillis, thanks for the Python3 code.
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
Offline 5,792 posts
since Oct 2004