Function Details: hex

Description


Returns the hexadecimal representation of an integer.


Extended Description


The hex() function converts 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. The returned string is a valid Python expression.


Read More about hex from Python Documentation

Function Signature


hex(x: int) -> str

Module: builtins

Parameters



Parameter List


  • x: int

Return


Returns a string containing the hexadecimal representation of the input integer.


Return Type


str

Output

Explanation

This example shows the basic usage of hex() with positive and negative integers.