Full name
hex
Library
Built-in
Syntax
hex(n)
Description
The hex function converts an integer to its hexadecimal representation in text and lowercase format, preceded by the characters "0x".
Parameters
- n: integer to convert to hexadecimal format
Examples
Several integers, positive and negative, are converted in this example:
If the argument is not an integer, the function returns an error of type TypeError:
Something similar happens if the argument is a text string, even if it represents an integer: