Faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 2 people (50%) answered Yes
Recently 0 of 1 people (0%) answered Yes

Entry

Outlining numbers with zeroes

Sep 15th, 2009 02:19
jick heir, 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))
http://sundhedernaeringguide.blogspot.com/
http://zdravevyzivypruvodce.blogspot.com/
http://guidasalutenutrizione.blogspot.com/
http://gesundheiternahrungpflege.blogspot.com/
http://soinssantenutrition.blogspot.com/
http://zdravljeprehranavodic.blogspot.com/
http://healthnutritionhoito.blogspot.com/
http://hlhnutgr.blogspot.com/
http://gezondheidvoedinggids.blogspot.com/
http://taplalkozas-egeszsegugyikezikonyv.blogspot.com/
http://hlthnutbg.blogspot.com/