Python hex() Function
Description
hex()The function is used to convert a decimal integer to hexadecimal, expressed as a string.
Syntax
hex syntax:
hex(x)
Parameter description:
- x -- decimal integer
Return Value
Returns a hexadecimal number, represented as a string.
Examples
The following example demonstrates how to use hex:
>>>hex(255)
'0xff'
>>> hex(-42)
'-0x2a'
>>> hex(1L)
'0x1L'
>>> hex(12)
'0xc'
>>> type(hex(12))
<class 'str'> # string
Python Built-in Functions