hex(x)

The hex() function converts an integer to its corresponding hexadecimal string.

Parameters

The hex() function takes one argument:

  • x - an integer (an object of type int or one that defines the __index__() method returning an integer)

Return Value

The hex() function returns the hexadecimal representation of an integer as a string.

The returned string begins with the prefix 0x, indicating it is in hexadecimal form.

Examples

hex(10)  # '0xa'
hex(-33)  # '-0x21'