![]() |
|
|
+ Search |
![]()
|
Mar 10th, 2005 00:23
Martin Miller, Nathan Wallace, Hans Nowak, Snippet 291, Jeff Bauer
"""
Packages: text.formatting
"""
"""
[...]
Here is a slightly different version which should
accomplish the same goals:
"""
def zfill(x, width):
return "%0*d" % (width, int(x))
# optional test routine ...
if __name__ == '__main__':
for x, width in [(12, 3), (-3, 3), (1, 6), ('17', 4)]:
print "zfill(%s, %d) = %s" % \
(x, width, zfill(x, width))