hex numbers??

David Brown david at no.westcontrol.spam.com
Fri Sep 27 08:33:43 EDT 2002


<jubafre at brturbo.com> wrote in message
news:mailman.1032881550.14068.python-list at python.org...
> >>> y=hex(x)
> >>> y
> '0xa'
> >>> type(y)
> <type 'str'>
>
> the hex() function put the hexadecimal number in a string type like this
'0xa', but the real hexadecimal number of 10 is 'a', why python puts a '0x',
and how i can get just the real hexadedcimal number, for example i want to
write in a file 10 in hexadecimal, but if i use hex(10) the result is '0xa'
as a string, is not the same as 'a'.
>
> '0xa' != 'a'
>
> x = [12,13,14]
> y = ['0xc', '0xd', '0xe']
>
> hex() create a list of string,  how i can write in a file just the real
value of hexadecimal number?
>

If you want to do the conversion over a list of numbers, try:
    map(lambda a : "%x" % a, x)







More information about the Python-list mailing list