In this tutorial we will learn about python hex() method and it uses with examples.
What is Python hax() method?
The hex() is the built-in python method used to convert an integer number into their corresponding lowercase hexadecimal string prefixed with “0x”.
The syntax of hex() method is:
Python hex() Method Parameters
The hex() method takes only one parameter.
- Integer – An integer number of which hexadecimal wants to return.
Let’s check some examples of the hex() method in python.
Example 1: How to use hex() method in python?
The output will be as follow:
We are returning a hexadecimal value on an integer, a zero, and a negative integer in the above program. Based on the integer value, you can see the hexadecimal string as shown in the output. Also, you can see that we are using the type method to check the data type of the hex() method output, which is a string.
Rules of hex() method
Hex () method converts an integer to the corresponding hexadecimal number in string form and returns it.
The returned hexadecimal string starts with the prefix 0x, indicating it’s in hexadecimal form.