Using %x to format number to hex and number of digits

Matty Sarro msarro at
Fri Nov 5 19:23:12 CET 2010

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.

num = 10
num = "%x"%(num)


num = 10
num = "%#x"%(num)


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list