On Fri, Nov 5, 2010 at 11:23 AM, Matty Sarro <msa...@gmail.com> wrote: > I'm currently trying to convert a digit from decimal to hex, however I need > the full 4 digit hex form. Python appears to be shortening the form. > Example: > > num = 10 > num = "%x"%(num) > print(num) > >>a > > num = 10 > num = "%#x"%(num) > print(num) > >>0xa > > I need it to output as 0x0a, and the exercise is requiring me to use %x to > format the string. Any help would be appreciated.
http://docs.python.org/release/2.5.2/lib/typesseq-strings.html What you're asking for is called "zero padding", so if I were you, I'd search the above page for the phrase "zero pad". -- Grant Edwards grant.b.edwards Yow! BARBARA STANWYCK makes at me nervous!! gmail.com -- http://mail.python.org/mailman/listinfo/python-list