Python hex() method is a built-in method. It is used to convert an integer value to a hexadecimal string. It returns a lowercase string prefix with ‘0x’.
Parameter | Description |
---|---|
x | It is an integer argument and if not given, define an index method that returns an integer. |
It returns a lowercase hexadecimal string.
Let’s first understand, how this method works and what does it return?
See, in the above example, hex() method returns hexadecimal string and the type of return value is string.
As we said, this method takes an integer argument only. If we give any other type of argument, it throws an error. See the example below.
TypeError: 'str' object cannot be interpreted as an integer