hex numbers??

Denis S. Otkidach ods at strana.ru
Tue Sep 24 11:43:58 EDT 2002


On Tue, 24 Sep 2002 jubafre at brturbo.com wrote:

> >>> 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?

>>> hex(10)[2:]
'a'
>>> '%x' % 10
'a'
>>> '%X' % 10
'A'

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]
http://diveinto.python.ru/ [ru]





More information about the Python-list mailing list