Printing a hex character and prefixing it correctly

Dave Angel davea at ieee.org
Fri May 15 13:49:56 EDT 2009


xamalek at yahoo.com wrote:
> If I have an integer k, for instance;
>
> k = 32 // BASE 10
>
> How do I get print to print it out in HEX and PREFIXED with 0x? What
> is the PROPER WAY?
>
> This does not work:
>
>   print "This is hex 32: ", int(k, 16)
>
> Xav
>
>   
How about
    print "This is hex 32: ", hex(k)


(This works in Python 2.6.2)




More information about the Python-list mailing list