Python hex() built-in function
From the Python 3 documentation
Convert an integer number to a lowercase hexadecimal string prefixed with “0x”. If x is not a Python int object, it has to define an __index__() method that returns an integer.
Introduction
The hex()
function in Python is a built-in function that converts an integer into its corresponding hexadecimal representation. The resulting string is prefixed with “0x” to indicate that it is a hexadecimal value. This function is useful when you need to work with hexadecimal numbers, which are common in low-level programming, such as when dealing with memory addresses or color codes.
Examples
>>> hex(1)
# '0x1'
>>> hex(10)
# '0xa'
>>> hex(100)
# '0x64'
>>> hex(1000)
# '0x3e8'