Next / Previous / Contents / TCC Help System / NM Tech homepage

20.18. hex(): Convert to base 16

Given an integer, this function returns a string displaying that value in hexadecimal (base 16).

>>> hex(15)
'0xf'
>>> hex(255)
'0xff'
>>> hex(256)
'0x100'
>>> hex(1325178541275812780L)
'0x1263fadcb8b713ac'

See also Section 9.4, “The string .format() method”: hexadecimal conversion is supported by specifying a type code of 'x' or 'X'.