Python hex() function
The hex() function in Python converts the specified number into a hexadecimal value.
Syntax
1 2 3 |
hex(x) |
Parameter
x: The parameter represents an Integer value.
Return
This function Returns hexadecimal string.
Example 1
1 2 3 4 5 6 7 |
# Python Program explaining # the hex() function print("The hexadecimal value of 123: "+ hex(123)) print("The hexadecimal form of a: " + hex(ord('a'))) print("The hexadecimal form of 13.9: "+ float.hex(3.9)) |
Output
1 2 3 4 5 |
The hexadecimal value of 1230x7b The hexadecimal form of a0x61 The hexadecimal form of 13.9 0x1.f333333333333p+1 |