How to use hex() function In Python
hex() function is one of the built-in functions in Python3, which is used to convert an integer number into its corresponding hexadecimal form.
Syntax : hex(x)
Parameters :
- x – an integer number (int object)
Returns : Returns hexadecimal string.
Errors and Exceptions :
TypeError : Returns TypeError when anything other than
integer type constants are passed as parameters.
Code :
Python3
# Python3 program to illustrate # hex() function print ( "The hexadecimal form of 69 is " + hex ( 69 )) |
Output:
The hexadecimal form of 69 is 0x45
Python Program to Convert Decimal to Hexadecimal
In this article, we will learn how to convert a decimal value(base 10) to a hexadecimal value (base 16) in Python.